Finalize v0.0.1: Make the bot relay the openai response to the matrix
user
This commit is contained in:
parent
f2efdebc90
commit
9d5d30e743
16
src/main.ts
16
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 () => {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue