tambahannya
This commit is contained in:
@@ -32,15 +32,9 @@ async function fetchWithTimeout(
|
||||
const FLOW_ID = "1";
|
||||
|
||||
async function flowAi({
|
||||
message,
|
||||
question,
|
||||
name,
|
||||
number,
|
||||
message
|
||||
}: {
|
||||
message: ProcessedIncomingMessage;
|
||||
question: string;
|
||||
name: string;
|
||||
number: string;
|
||||
}) {
|
||||
const flow = await prisma.chatFlows.findUnique({
|
||||
where: { id: FLOW_ID },
|
||||
@@ -55,7 +49,7 @@ async function flowAi({
|
||||
logger.info("[POST] flow found");
|
||||
|
||||
await client.markMessageAsRead(message.id);
|
||||
await client.sendTypingIndicator(message.from);
|
||||
await client.sendTypingIndicatorWithDuration(message.from, 5000);
|
||||
|
||||
const { flowUrl, flowToken } = flow;
|
||||
|
||||
@@ -69,10 +63,10 @@ async function flowAi({
|
||||
},
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
question,
|
||||
question: message.text,
|
||||
overrideConfig: {
|
||||
sessionId: `${_.kebabCase(name)}_x_${number}`,
|
||||
vars: { userName: _.kebabCase(name), userPhone: number },
|
||||
sessionId: `${_.kebabCase(message.contact?.name)}_x_${message.from}`,
|
||||
vars: { userName: _.kebabCase(message.contact?.name), userPhone: message.from },
|
||||
},
|
||||
}),
|
||||
}
|
||||
@@ -85,9 +79,9 @@ async function flowAi({
|
||||
await prisma.waHook.create({
|
||||
data: {
|
||||
data: JSON.stringify({
|
||||
question,
|
||||
name,
|
||||
number,
|
||||
question: message.text,
|
||||
name: message.contact?.name,
|
||||
number: message.from,
|
||||
answer: result.text,
|
||||
flowId: flow.defaultFlow,
|
||||
}),
|
||||
@@ -95,7 +89,8 @@ async function flowAi({
|
||||
});
|
||||
|
||||
if (flow.waPhoneNumberId && flow.waToken && flow.active) {
|
||||
await client.sendText(number, result.text);
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
await client.sendText(message.from, result.text);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[POST] Error parsing AI response ${error}`);
|
||||
@@ -168,9 +163,6 @@ const WaHookRoute = new Elysia({
|
||||
// gunakan void agar tidak ada warning “unawaited promise”
|
||||
void flowAi({
|
||||
message: webhook[0],
|
||||
question: messageQuestion,
|
||||
name: name || "default_name",
|
||||
number: from,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user