This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from muharamdani/feature/auto-relogin-and-more-…
…modular-code Feature | More modular code and add auto re-login feature
- Loading branch information
Showing
21 changed files
with
858 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
{"quora_formkey":"","quora_cookie":""} | ||
{ | ||
"stream_response": true, | ||
"quora_formkey": "", | ||
"quora_cookie": "", | ||
"channel_name": "", | ||
"app_settings": { | ||
"formkey": "", | ||
"tchannelData": { | ||
"minSeq": "", | ||
"channel": "", | ||
"channelHash": "", | ||
"boxName": "", | ||
"baseHost": "", | ||
"targetUrl": "", | ||
"enableWebsocket": true | ||
} | ||
}, | ||
"chat_ids": { | ||
"a2": 0, | ||
"capybara": 0, | ||
"nutria": 0, | ||
"chinchilla": 0 | ||
}, | ||
"auto_login": true, | ||
"email": "", | ||
"sid_token": "" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ChatBot from "./index.js"; | ||
const bot = new ChatBot(); | ||
await bot.startCli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import ChatBot from "./index.js"; | ||
const bot = new ChatBot(); | ||
// Used to check if the formkey and cookie is available | ||
const isFormkeyAvailable = await bot.getCredentials(); | ||
if (!isFormkeyAvailable) { | ||
console.log("Formkey and cookie not available"); | ||
// Set the formkey, cookie and any other data needed and save it into config.json | ||
await bot.setCredentials(); | ||
const chatId = await bot.getChatId("a2"); | ||
console.log(chatId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ChatBot from "./index.js"; | ||
const bot = new ChatBot(); | ||
// Used to check if the formkey and cookie is available | ||
const isFormkeyAvailable = await bot.getCredentials(); | ||
if (!isFormkeyAvailable) { | ||
await bot.setCredentials(); | ||
await bot.subscribe(); // for websocket(stream response) purpose | ||
await bot.login("auto"); | ||
} | ||
const ai = "a2"; // bot list are in config.example.json, key "chat_ids" | ||
// If you want to clear the chat context, you can use this | ||
await bot.clearContext(ai); | ||
// If you want to get the response (with stream), you can use this | ||
// NOTE that you need to call this before you send the message | ||
// await getUpdatedSettings(bot.config.channel_name, bot.config.quora_cookie); | ||
// await bot.subscribe(); | ||
// const ws = await connectWs(); | ||
// If you want to send a message, you can use this | ||
await bot.sendMsg(ai, "Hello, who are you?"); | ||
// If you want to get the response (without stream), you can use this | ||
const response = await bot.getResponse(ai); | ||
console.log(response); | ||
// // If you want to get the response (with stream), you can use this | ||
// process.stdout.write("Response: "); | ||
// await listenWs(ws); | ||
// console.log('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ChatBot from "./index.js"; | ||
const bot = new ChatBot(); | ||
// Used to check if the formkey and cookie is available | ||
const isFormkeyAvailable = await bot.getCredentials(); | ||
if (!isFormkeyAvailable) { | ||
console.log("Formkey and cookie not available"); | ||
// Set the formkey, cookie and any other data needed and save it into config.json | ||
await bot.setCredentials(); | ||
const myEmail = "[email protected]"; | ||
const signInStatus = await bot.sendVerifCode(null, myEmail); | ||
// After you get the verification code, you can use this step to log in | ||
// then check signInStatus | ||
let loginStatus = "invalid_verification_code"; | ||
while (loginStatus !== "success") { | ||
if (signInStatus === 'user_with_confirmed_phone_number_not_found') { | ||
loginStatus = await bot.signUpWithVerificationCode(myEmail, null, 123456); // 123456 is the verification code | ||
} | ||
else { | ||
loginStatus = await bot.signInOrUp(myEmail, null, 123456); // 123456 is the verification code | ||
} | ||
} | ||
} | ||
const ai = "a2"; // bot list are in config.example.json, key "chat_ids" | ||
// If you want to clear the chat context, you can use this | ||
await bot.clearContext(ai); | ||
// If you want to get the response (with stream), you can use this | ||
// NOTE that you need to call this before you send the message | ||
// await getUpdatedSettings(bot.config.channel_name, bot.config.quora_cookie); | ||
// await bot.subscribe(); | ||
// const ws = await connectWs(); | ||
// If you want to send a message, you can use this | ||
await bot.sendMsg(ai, "Hello, who are you?"); | ||
// If you want to get the response (without stream), you can use this | ||
const response = await bot.getResponse(ai); | ||
console.log(response); | ||
// // If you want to get the response (with stream), you can use this | ||
// process.stdout.write("Response: "); | ||
// await listenWs(ws); | ||
// console.log('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.