Finalize v0.0.1: Make the bot relay the openai response to the matrix
user
This commit is contained in:
parent
f2efdebc90
commit
9d5d30e743
14
src/main.ts
14
src/main.ts
|
@ -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 () => {
|
|
||||||
|
const responseFromAi = await callOpenAiAPI({
|
||||||
|
prompt: body,
|
||||||
|
bearer: openaiApiKey,
|
||||||
|
});
|
||||||
|
|
||||||
await client.setTyping(roomId, false);
|
await client.setTyping(roomId, false);
|
||||||
await client.replyNotice(roomId, event, "Hello world!");
|
await client.replyNotice(roomId, event, responseFromAi);
|
||||||
}, 1500);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue