Finalize v0.0.1: Make the bot relay the openai response to the matrix

user
This commit is contained in:
Nikhil Nawgiri 2024-08-25 03:44:14 +02:00
parent f2efdebc90
commit 9d5d30e743

View file

@ -43,19 +43,23 @@ interface Event {
// This is the command handler we registered a few lines up // This is the command handler we registered a few lines up
async function handleCommand(roomId: string, event: Event) { async function handleCommand(roomId: string, event: Event) {
console.log("event:", event); // console.log("event:", event);
// Don't handle unhelpful events (ones that aren't text messages, are redacted, or sent by us) // Don't handle unhelpful events (ones that aren't text messages, are redacted, or sent by us)
if (event.content?.msgtype !== 'm.text') return; if (event.content?.msgtype !== 'm.text') return;
if (event.sender === await client.getUserId()) return; if (event.sender === await client.getUserId()) return;
// Check to ensure that the `!hello` command is being run // Check to ensure that the `!hello` command is being run
const body = event.content.body; const body = event.content.body;
if (!body?.startsWith("!hello")) return; // if (!body?.startsWith("!hello")) return;
// Now that we've passed all the checks, we can actually act upon the command // Now that we've passed all the checks, we can actually act upon the command
await client.setTyping(roomId, true); await client.setTyping(roomId, true);
setTimeout(async () => {
await client.setTyping(roomId, false); const responseFromAi = await callOpenAiAPI({
await client.replyNotice(roomId, event, "Hello world!"); prompt: body,
}, 1500); bearer: openaiApiKey,
});
await client.setTyping(roomId, false);
await client.replyNotice(roomId, event, responseFromAi);
} }