Poe API fixed

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

44
poe.js
View File

@@ -252,24 +252,44 @@ class Client {
} }
} }
on_message(ws, msg) { async on_message(ws, msg) {
const data = JSON.parse(msg); try {
const message = JSON.parse(data["messages"][0])["payload"]["data"]["messageAdded"]; const data = JSON.parse(msg);
const copiedDict = Object.assign({}, this.active_messages); if (!('messages' in data)) {
for (const [key, value] of Object.entries(copiedDict)) {
//add the message to the appropriate queue
if (value === message["messageId"] && key in this.message_queues) {
this.message_queues[key].push(message);
return; return;
} }
//indicate that the response id is tied to the human message id for (const message_str of data["messages"]) {
else if (key !== "pending" && value === null && message["state"] !== "complete") { const message_data = JSON.parse(message_str);
this.active_messages[key] = message["messageId"];
this.message_queues[key].push(message); 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)) {
//add the message to the appropriate queue
if (value === message["messageId"] && key in this.message_queues) {
this.message_queues[key].push(message);
return;
}
//indicate that the response id is tied to the human message id
else if (key !== "pending" && value === null && message["state"] !== "complete") {
this.active_messages[key] = message["messageId"];
this.message_queues[key].push(message);
}
}
} }
} }
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) { async *send_message(chatbot, message, with_chat_break = false, timeout = 20) {