diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..97cc744 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +QUORA_FORMKEY=your_formkey +MB_COOKIE=your_cookie \ No newline at end of file diff --git a/.gitignore b/.gitignore index 54ab241..e686c45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .idea config.json +.env \ No newline at end of file diff --git a/README.md b/README.md index 72b371d..28e531f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Quora Poe - -- Since it +This is a CLI tool to call the Quora Poe API through GraphQL. It is a work in progress, and currently only supports the following: +- Chat with 3 types of bots (Claude, Capybara, and Nutria) +- Clear the chat history ## Installation - -To install this app, run: +- Copy the .env.example file to .env and fill in the required fields +- Run the following command to install the dependencies: ``` npm install @@ -20,9 +21,11 @@ npm start ## Requirements -To use this API, you will need to have the following cookies: -- Quora-Formkey: This is obtained by logging in to Quora.com, viewing the page source, and finding the "formkey" dictionary key. Use its value in the Quora-Formkey field. +To use this API, you will need to have the following: +- Quora-Formkey: This is obtained by logging in to Quora.com, viewing the page source, and finding the "formkey" dictionary key. - Cookie: 'm-b=xxxx' - This is the value of the cookie with the key m-b, which is present in the list of cookies used on Quora.com, you can simply inspect cookies in Chrome to get it. +- Put the above two in a .env file in the root directory of the project + Note: Next plan is to semi automate this things ## Dependencies @@ -39,5 +42,7 @@ Note: Next plan is to semi automate this things - prompts ## Contributing +Since I do not own apple devices, I am unable to reverse engineer the app to find the endpoints/requests made by the app. +If you are able to do so, please contribute to this repo by adding new features or fixing bugs. To contribute to this repo, fork first and create a pull request. diff --git a/dist/index.js b/dist/index.js index ed87b79..e5f3b05 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4,7 +4,9 @@ import makeSession from "fetch-cookie"; import fetch from "cross-fetch"; import prompts from "prompts"; import ora from "ora"; +import * as dotenv from "dotenv"; import { readFileSync } from "fs"; +dotenv.config(); const spinner = ora({ color: "cyan", }); @@ -32,8 +34,8 @@ class ChatBot { "apollographql-client-name": "com.quora.app.Experts-apollo-ios", "Connection": "keep-alive", "Content-Type": "application/json", - "Quora-Formkey": "fil this", - "Cookie": "fill this" + "Quora-Formkey": process.env.QUORA_FORMKEY || "", + "Cookie": process.env.MB_COOKIE || "", }, }), cache: new InMemoryCache(), @@ -60,8 +62,12 @@ class ChatBot { { title: "Claude - a2", value: "a2" }, { title: "Capybara (logical)", value: "capybara" }, { title: "Nutria (simpler)", value: "nutria" }, + { title: "exit", value: "exit" } ], }); + if (bot === "exit") { + return; + } await this.getChatId(bot); let helpMsg = "Available commands: !help !exit, !clear, !submit" + "\n!help - show this message" + diff --git a/package-lock.json b/package-lock.json index dfc31c0..27abd2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "cheerio": "^1.0.0-rc.12", "cli-spinners": "^2.7.0", "cross-fetch": "^3.1.5", + "dotenv": "^16.0.3", "fetch-cookie": "^2.1.0", "graphql": "^16.6.0", "graphql-tag": "^2.12.6", @@ -936,6 +937,14 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -2686,6 +2695,11 @@ "domhandler": "^5.0.1" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index d909404..20f1829 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "cheerio": "^1.0.0-rc.12", "cli-spinners": "^2.7.0", "cross-fetch": "^3.1.5", + "dotenv": "^16.0.3", "fetch-cookie": "^2.1.0", "graphql": "^16.6.0", "graphql-tag": "^2.12.6", diff --git a/src/index.ts b/src/index.ts index 905cab0..4cf2719 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,10 @@ import makeSession from "fetch-cookie"; import fetch from "cross-fetch"; import prompts from "prompts"; import ora from "ora"; -import https from 'https'; -import {readFileSync, writeFile} from "fs"; +import * as dotenv from "dotenv"; +import {readFileSync} from "fs"; + +dotenv.config(); const spinner = ora({ color: "cyan", @@ -36,8 +38,8 @@ class ChatBot { "apollographql-client-name": "com.quora.app.Experts-apollo-ios", "Connection": "keep-alive", "Content-Type": "application/json", - "Quora-Formkey": "fil this", - "Cookie": "fill this" + "Quora-Formkey": process.env.QUORA_FORMKEY || "", + "Cookie": process.env.MB_COOKIE || "", }, }), cache: new InMemoryCache(), @@ -65,8 +67,14 @@ class ChatBot { {title: "Claude - a2", value: "a2"}, {title: "Capybara (logical)", value: "capybara"}, {title: "Nutria (simpler)", value: "nutria"}, + {title: "exit", value: "exit"} ], }); + + if (bot === "exit") { + return; + } + await this.getChatId(bot); let helpMsg = "Available commands: !help !exit, !clear, !submit" +