Skip to content

Commit

Permalink
🚑 (whatsapp) Rename 'origin' parameter to 'callFrom' in webhook handl…
Browse files Browse the repository at this point in the history
…ers and related functions

Closes #1896
  • Loading branch information
baptisteArno committed Nov 23, 2024
1 parent a37cdb3 commit 4089831
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
workspaceId: typebot.workspace.id,
sessionId: chatSession.id,
credentialsId: typebot.whatsAppCredentialsId,
origin: "webhook",
callFrom: "webhook",
});
return res.status(200).send("OK");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
},
},
sessionId: chatSession.id,
origin: "webhook",
callFrom: "webhook",
});
return res.status(200).send("OK");
}
Expand Down
5 changes: 3 additions & 2 deletions packages/whatsapp/src/resumeWhatsAppFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Props = {
phoneNumberId?: string;
workspaceId?: string;
contact?: NonNullable<SessionState["whatsApp"]>["contact"];
origin?: "webhook";
callFrom?: "webhook";
};

const isMessageTooOld = (receivedMessage: WhatsAppIncomingMessage) => {
Expand All @@ -46,6 +46,7 @@ export const resumeWhatsAppFlow = async ({
credentialsId,
phoneNumberId,
contact,
callFrom,
}: Props) => {
if (isMessageTooOld(receivedMessage))
throw new WhatsAppError("Message is too old", {
Expand Down Expand Up @@ -81,7 +82,7 @@ export const resumeWhatsAppFlow = async ({
session?.updatedAt.getTime() + session.state.expiryTimeout < Date.now();

if (aggregationResponse.status === "treat as unique message") {
if (session?.isReplying && origin !== "webhook") {
if (session?.isReplying && callFrom !== "webhook") {
if (!isSessionExpired) throw new WhatsAppError("Is in reply state");
} else {
await setIsReplyingInChatSession({
Expand Down

0 comments on commit 4089831

Please sign in to comment.