Poe API fixed

This commit is contained in:
SillyLossy
2023-04-05 12:46:35 +03:00
parent 4cfad2029c
commit ce1f33679e

24
poe.js
View File

@@ -252,9 +252,22 @@ class Client {
}
}
on_message(ws, msg) {
async on_message(ws, msg) {
try {
const data = JSON.parse(msg);
const message = JSON.parse(data["messages"][0])["payload"]["data"]["messageAdded"];
if (!('messages' in data)) {
return;
}
for (const message_str of data["messages"]) {
const message_data = JSON.parse(message_str);
if (message_data["message_type"] != "subscriptionUpdate"){
continue;
}
const message = message_data["payload"]["data"]["messageAdded"]
const copiedDict = Object.assign({}, this.active_messages);
for (const [key, value] of Object.entries(copiedDict)) {
@@ -271,6 +284,13 @@ class Client {
}
}
}
}
catch (err) {
console.log('Error occurred in onMessage', err);
this.disconnect_ws();
await this.connect_ws();
}
}
async *send_message(chatbot, message, with_chat_break = false, timeout = 20) {
//if there is another active message, wait until it has finished sending