diff --git a/functions/.env.local.test b/functions/.env.local.test index 9b774d21..a5a211f6 100644 --- a/functions/.env.local.test +++ b/functions/.env.local.test @@ -13,4 +13,5 @@ EMBEDDER_HOST=http://embedder-server:12344 TELEGRAM_REPORT_CHANNEL_ID=111111111 TEST_IMAGE_URL=TEST HASHIDS_SALT=SALT -WEBHOOK_PATH=whatsapp \ No newline at end of file +WEBHOOK_PATH_WHATSAPP=whatsapp +WEBHOOK_PATH_TELEGRAM=telegram \ No newline at end of file diff --git a/functions/src/definitions/batchJobs/batchJobs.ts b/functions/src/definitions/batchJobs/batchJobs.ts index 27077fd7..9b15b3f0 100644 --- a/functions/src/definitions/batchJobs/batchJobs.ts +++ b/functions/src/definitions/batchJobs/batchJobs.ts @@ -9,6 +9,7 @@ import { Timestamp } from "firebase-admin/firestore" import { getCount } from "../common/counters" import { getThresholds } from "../common/utils" import { defineString } from "firebase-functions/params" +import { onSchedule } from "firebase-functions/v2/scheduler" const runtimeEnvironment = defineString("ENVIRONMENT") @@ -125,28 +126,35 @@ async function interimPromptHandler() { } } -const checkSessionExpiring = functions - .region("asia-southeast1") - .runWith({ secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"] }) - .pubsub.schedule("1 * * * *") - .timeZone("Asia/Singapore") - .onRun(checkConversationSessionExpiring) +const checkSessionExpiring = onSchedule( + { + schedule: "1 * * * *", + timeZone: "Asia/Singapore", + secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], + region: "asia-southeast1", + }, + checkConversationSessionExpiring +) -const scheduledDeactivation = functions - .region("asia-southeast1") - .runWith({ +const scheduledDeactivation = onSchedule( + { + schedule: "11 20 * * *", + timeZone: "Asia/Singapore", secrets: ["WHATSAPP_CHECKERS_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], - }) - .pubsub.schedule("11 20 * * *") - .timeZone("Asia/Singapore") - .onRun(deactivateAndRemind) + region: "asia-southeast1", + }, + deactivateAndRemind +) -const sendInterimPrompt = functions - .region("asia-southeast1") - .runWith({ secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"] }) - .pubsub.schedule("*/20 * * * *") - .timeZone("Asia/Singapore") - .onRun(interimPromptHandler) +const sendInterimPrompt = onSchedule( + { + schedule: "2,22,42 * * * *", + timeZone: "Asia/Singapore", + secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], + region: "asia-southeast1", + }, + interimPromptHandler +) export { checkSessionExpiring, diff --git a/functions/src/definitions/common/parameters/userResponses.json b/functions/src/definitions/common/parameters/userResponses.json index 5134f414..eebf69cf 100644 --- a/functions/src/definitions/common/parameters/userResponses.json +++ b/functions/src/definitions/common/parameters/userResponses.json @@ -13,7 +13,7 @@ }, "ERROR": { "en": "Oops, we encountered an error assessing this message.\n\nYou can try sending the message in again, or report the error via our form at https://bit.ly/checkmate-feedback. Sorry about that! 😔", - "cn": "抱歉,查友在评估您提供的短信时发生问题。\n\n欢迎您稍后重试,或者通过这份表格向我们反馈:https://bit.ly/checkmate-feedback。对此造成的不便,我们非常抱歉!😔" + "cn": "抱歉,查友在评估您提供的短信时发生了问题。\n\n欢迎您稍后重试,或者通过这份表格向我们反馈:https://bit.ly/checkmate-feedback。对此造成的不便,我们非常抱歉!😔" }, "MESSAGE_NOT_YET_ASSESSED": { "en": "Hello! 👋 Thanks for sending this in! Our *CheckMates🕵🏻 will review this* and *provide the results soon*.", @@ -29,7 +29,7 @@ }, "SPAM": { "en": "{{thanks}}{{matched}}{{methodology}}spam!🚧{{image_caveat}}\n\nIt's likely harmless, but you should always make sure 🧐\n\nThank you for keeping Singapore safe!", - "cn": "{{thanks}}{{matched}}{{methodology}}是垃圾信息!🚧{{image_caveat}}\n\n虽然它看似无害,但仍然请您保持警惕 🧐\n\n感谢您对新加坡网络安全的支持和贡献!" + "cn": "{{thanks}}{{matched}}{{methodology}}是垃圾信息!🚧{{image_caveat}}\n\n虽然它看似无害,但请仍然保持警惕 🧐\n\n感谢您对新加坡网络安全的支持和贡献!" }, "LEGITIMATE": { "en": "{{thanks}}{{matched}}{{methodology}}*from a legitimate source*.✅{{image_caveat}}\n\nThank you for keeping Singapore safe!", @@ -76,8 +76,8 @@ "cn": "另外{{second}}%的人认为这条短信{{category}}{{info_placeholder}}。" }, "INTERIM_TEMPLATE": { - "en": "At this time, {{%voted}}% of our CheckMates have assessed and voted on this message. The majority think that this is {{prelim_assessment}}{{info_placeholder}}. \n\nNOTE: This is a *preliminary result*. We aim to provide you with a more credible final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.{{get_feedback}}", - "cn": "目前,{{%voted}}%的查哥查妹已经对这条短信进行投票评估。大多数人认为这条短信{{prelim_assessment}}{{info_placeholder}}。\n\n注意:这只是初步结果。我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。{{get_feedback}}" + "en": "At this time, {{%voted}}% of our CheckMates have assessed and voted on this message. The majority think that this is {{prelim_assessment}}{{info_placeholder}}. \n\nNOTE: This is a *preliminary result*. We aim to provide you with a more credible final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.", + "cn": "目前,{{%voted}}%的查哥查妹已经对这条短信进行投票评估。大多数人认为这条短信{{prelim_assessment}}{{info_placeholder}}。\n\n注意:这只是初步结果。我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。" }, "INFO_PLACEHOLDER": { "en": ", with an average score of {{score}} on a scale of 0-5 (5 = completely true)", @@ -85,23 +85,11 @@ }, "INTERIM_TEMPLATE_UNSURE": { "en": "At this time, {{%voted}}% of our CheckMates have assessed and voted on this message. Unfortunately, our CheckMates either have not reached any clear consensus, or are still unsure how to assess the message at this time.\n\nIf you haven't done so, you could send in the message with more context, e.g. sending in a screenshot containing the sender's number.", - "cn": "目前,{%voted}}%的查哥查妹已经对这条短信进行投票评估。不幸的是,他们无法达成一致,或缺乏足够的信息进行评估。\n\n如果您能提供更多信息,例如发信人电话号码或截图,将有助于我们更好地评估。" - }, - "INTERIM_FEEDBACK": { - "en": "\n\nThanks for trusting CheckMate! 👋🏼 If this interim update was useful to you, we'd appreciate it if you'd let us know by tapping on “Yes, it's useful” below. Otherwise, tap on “No, it's not” to continue waiting for the final result. Either way, you can continue to request more updates as more votes come in.", - "cn": "感谢您对查友的信任!👋🏼 如果这个初步结果对您有帮助,请点击“有帮助”。否则,请点击“没帮助”以继续等待最终结果。您可以在最终结果发布之前随时要求最新的初步结果。" + "cn": "目前,{%voted}}%的查哥查妹已经对这条短信进行投票评估。但是,他们无法达成一致,或缺乏足够的信息进行评估。\n\n如果您能提供更多信息,例如发信人电话号码或截图,将有助于我们更好地评估。" }, "INTERIM_PROMPT": { "en": "Thanks for waiting! We are currently still pending the assessment from some of our network of trusted CheckMate volunteers and will only be able to provide a credible final result once enough votes have come in. \n\nYou may press the button below *to get an interim update of the preliminary result*. However, do note that there may be discrepancies between the preliminary and the final result, and *the preliminary result should be interpreted with caution*. We appreciate your patience and hope to deliver the final result to you soon! 💪🏼", - "cn": "感谢您的耐心等待!查哥查妹正在对您提交的短信进行投票评估。我们将在足够多的查哥查妹票后,为您提供最终结果。\n\n在最终结果发布之前,您可以点击获取初步结果。请注意,初步结果和最终结果之间可能存在差异,应谨慎解读初步结果。我们感谢您的耐心,并希望尽快为您提供最终结果!💪🏼" - }, - "INTERIM_USEFUL": { - "en": "Thanks for your valuable feedback! We will provide you with the final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.\n\nIn the meantime, if you'd like another update after more votes come in, just tap the button below to request one.", - "cn": "感谢您的反馈!我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。\n\n请点击下方按钮再次获取最新的初步结果。" - }, - "INTERIM_NOT_USEFUL": { - "en": "Sorry to hear that, but thanks anyway for your valuable feedback! We will provide you with the final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.\n\nIf you'd like still another update after more votes come in, just tap the button below to request one.", - "cn": "感谢您的反馈!我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,尽快为您提供最终的结果。\n\n请点击下方按钮再次获取最新的初步结果。" + "cn": "感谢您的耐心等待!查哥查妹正在对您提交的短信进行投票评估。我们将在足够多的查哥查妹投票后,为您提供最终结果。\n\n在最终结果发布之前,您可以点击“获取初步结果”。请注意,初步结果和最终结果可能存在差异,应谨慎解读初步结果。我们感谢您的耐心,并会尽快提供最终结果!💪🏼" }, "ALREADY_REPLIED": { "en": "CheckMate has already provided a final response to this message.", @@ -112,16 +100,16 @@ "cn": "我们不会将您的短信发送给ScamShield。感谢您与我们分享这条短信,也感谢您对新加坡网络安全的支持和贡献。" }, "MENU": { - "en": "{{prefix}}\n\nIf you know what to do, please go ahead! Else, select \"Menu\" below to see what CheckMate can do! 👈\n\nDo note that CheckMate *is designed to check dubious messages you send in. It cannot converse freely with you*.\n\nAnytime you need a refresher on what CheckMate can do, type \"menu\" to get here again! 😊", - "cn": "{{prefix}}\n\n请点击“菜单\"查看查友的功能!👈\n\n请注意,查友仅能评估您发送的短信,它无法与您进行对话。\n\n您只需输入\"菜单\"即可随时返回这里,查看查友的功能!😊" + "en": "{{prefix}}\n\nSelect \"Menu\" below to see what CheckMate can do! 👈\n\nDo note that CheckMate *is designed to check dubious messages you send in. It cannot converse freely with you*.\n\nAnytime you need a refresher on what CheckMate can do, type \"menu\" to get here again! 😊", + "cn": "{{prefix}}\n\n请点击“菜单\"查看查友的功能!👈\n\n请注意,查友只评估您发送的短信,它无法与您进行对话。\n\n您只需输入\"菜单\"即可随时返回这里,查看查友的功能!😊" }, "NEW_USER_PREFIX_EN": { "en": "Hello and welcome to CheckMate! We're glad you've joined us to battle scams and misinformation😊.", "cn": "Hello and welcome to CheckMate! We're glad you've joined us to battle scams and misinformation😊." }, "NEW_USER_PREFIX_CN": { - "en": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n", - "cn": "您好,欢迎使用查友!很高兴您加入我们,一起参与反击诈骗和虚假信息😊。\n" + "en": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n\n", + "cn": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n\n" }, "LANGUAGE_SELECTION": { "en": "{{new_user_en}}\n\nPlease select your preferred language.\n\n{{new_user_cn}}请选择语言。", @@ -141,7 +129,7 @@ }, "PROCEED_TO_SEND": { "en": "Nice! Just send/forward us the message. We'll help you check and/or report it! ✅✅\n\nIf you like, you can also send in screenshots 📷 or other images 🖼️! This can help to capture the sender's number, or a full conversation, which could help our CheckMates' assessment.\n\nOne last thing: by continuing to use CheckMate, you're agreeing to our privacy policy, which can be found at https://checkmate.sg/privacy-policy. In short, we only collect the messages sent to us and your number to facilitate a response!", - "cn": "好的!您只需将短信发送给查友,我们会对其进行评估!✅✅\n\n除了文字信息,您也可以发送截图📷或其他图片🖼️!这有助于查哥查妹通过发信人号码或完整的对话内容做出判断。\n\n最后,使用查友即表示您已同意我们的隐私政策。您可在 https://checkmate.sg/privacy-policy 查看我们的隐私政策。基本上,我们只收集您发送的消息以及您的手机号码,以便回复您!" + "cn": "好的!您只需将短信发送给查友,我们会对此进行评估!✅✅\n\n除了文字信息,您也可以发送截图📷或其他图片🖼️!这有助于查哥查妹通过发信人号码或完整的对话内容做出评判。\n\n最后,使用查友即表示您已同意我们的隐私政策。您可在 https://checkmate.sg/privacy-policy 查看我们的隐私政策。基本上,我们只收集您发送的消息以及您的手机号码,以便回复您!" }, "HOW_TO": { "en": "Check out https://youtube.com/shorts/gFeO_qFOchs?feature=share to see how CheckMate works!\n\nDone? You're now ready to use CheckMate! Let's do our part in the fight against scams and misinformation! 💪", @@ -168,12 +156,12 @@ "cn": "您是否已经开始使用查友?点击此链接进行注册!{{link}}" }, "REFERRAL_PREPOPULATED_PREFIX": { - "en": "Welcome to CheckMate! Send in this entire message (including the code) to get started, and credit your friend with your referral. Code:", - "cn": "欢迎使用查友!请发送这条短信(包括推荐人代码)以开始使用。代码:" + "en": "Welcome to CheckMate! Send in this message to get started, and credit your friend with your referral.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", + "cn": "Welcome to CheckMate! Send in this message to get started, and credit your friend with your referral.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:" }, "GENERIC_PREPOPULATED_PREFIX": { - "en": "Welcome to Checkmate! Send in this entire message (including the code) to get started. Code:", - "cn": "欢迎使用查友!请发送这条短信(包括代码)以开始使用。代码:" + "en": "Welcome to CheckMate! Send in this message to get started.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", + "cn": "Welcome to CheckMate! Send in this message to get started.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:" }, "REFERRAL_INVALID": { "en": "Sorry, referrals are only credited upon your first interaction with CheckMate.", diff --git a/functions/src/definitions/common/pubsub.ts b/functions/src/definitions/common/pubsub.ts index 5d5be0d0..cf1e212f 100644 --- a/functions/src/definitions/common/pubsub.ts +++ b/functions/src/definitions/common/pubsub.ts @@ -13,7 +13,11 @@ if (env === "PROD") { }) } -async function publishToTopic(topicName: string, messageData: object) { +async function publishToTopic( + topicName: string, + messageData: object, + source: string +) { if (env !== "PROD") { const [exists] = await pubsub.topic(topicName).exists() //Doesn't seem to autocreate in emulator if (!exists) { @@ -23,7 +27,12 @@ async function publishToTopic(topicName: string, messageData: object) { const topic = pubsub.topic(topicName) try { // Publish the message - const messageId = await topic.publishMessage({ json: messageData }) + const messageId = await topic.publishMessage({ + json: messageData, + attributes: { + source: source, + }, + }) functions.logger.log(`Message ${messageId} published.`) } catch (error) { functions.logger.log(`Error publishing message: ${error}`) diff --git a/functions/src/definitions/common/responseUtils.ts b/functions/src/definitions/common/responseUtils.ts index 3aa18535..13fd54dd 100644 --- a/functions/src/definitions/common/responseUtils.ts +++ b/functions/src/definitions/common/responseUtils.ts @@ -76,43 +76,6 @@ function getInfoLiner(truthScore: null | number, infoPlaceholder: string) { ) } -async function respondToInterimFeedback( - instancePath: string, - isUseful: string -) { - const instanceRef = db.doc(instancePath) - const instanceSnap = await instanceRef.get() - const data = instanceSnap.data() - const from = data?.from ?? null - const responses = await getResponsesObj("user", from) - if (!data) { - functions.logger.log("Missing data in respondToInterimFeedback") - return - } - const buttons = [ - { - type: "reply", - reply: { - id: `sendInterim_${instancePath}`, - title: responses.BUTTON_ANOTHER_UPDATE, - }, - }, - ] - let response - switch (isUseful) { - case "yes": - response = responses?.INTERIM_USEFUL - await instanceRef.update({ isInterimUseful: true }) - break - default: - response = responses?.INTERIM_NOT_USEFUL - await instanceRef.update({ isInterimUseful: false }) - break - } - - await sendWhatsappButtonMessage("user", from, response, buttons, data.id) -} - async function respondToRationalisationFeedback( instancePath: string, isUseful: string @@ -558,18 +521,13 @@ async function sendInterimUpdate(instancePath: string) { return } const updateObj: { - isInterimUseful?: boolean isMeaningfulInterimReplySent?: boolean prelimAssessment?: string isInterimReplySent?: boolean } = {} let finalResponse - let isFirstMeaningfulReply = false if (primaryCategory === "unsure") { finalResponse = responses.INTERIM_TEMPLATE_UNSURE - if (data.isInterimUseful === null) { - updateObj.isInterimUseful = false - } if (data.isMeaningfulInterimReplySent === null) { updateObj.isMeaningfulInterimReplySent = false } @@ -577,48 +535,22 @@ async function sendInterimUpdate(instancePath: string) { finalResponse = responses.INTERIM_TEMPLATE if (!data.isMeaningfulInterimReplySent) { updateObj.isMeaningfulInterimReplySent = true - isFirstMeaningfulReply = true } } - const getFeedback = - (data.isInterimUseful === null || isFirstMeaningfulReply) && - primaryCategory !== "unsure" && - FEEDBACK_FEATURE_FLAG finalResponse = finalResponse .replace("{{prelim_assessment}}", prelimAssessment) .replace("{{info_placeholder}}", infoPlaceholder) .replace("{{%voted}}", percentageVoted) - .replace("{{get_feedback}}", getFeedback ? responses.INTERIM_FEEDBACK : "") - let buttons - if (getFeedback) { - buttons = [ - { - type: "reply", - reply: { - id: `feedbackInterim_${instancePath}_yes`, - title: responses.BUTTON_USEFUL, - }, - }, - { - type: "reply", - reply: { - id: `feedbackInterim_${instancePath}_no`, - title: responses.BUTTON_NOT_USEFUL, - }, - }, - ] - } else { - buttons = [ - { - type: "reply", - reply: { - id: `sendInterim_${instancePath}`, - title: responses.BUTTON_ANOTHER_UPDATE, - }, + const buttons = [ + { + type: "reply", + reply: { + id: `sendInterim_${instancePath}`, + title: responses.BUTTON_ANOTHER_UPDATE, }, - ] - } + }, + ] await sendWhatsappButtonMessage("user", from, finalResponse, buttons, data.id) if (!instanceSnap.get("isInterimReplySent")) { updateObj.isInterimReplySent = true @@ -917,7 +849,6 @@ export { sendInterimUpdate, sendVotingStats, sendReferralMessage, - respondToInterimFeedback, sendRationalisation, respondToRationalisationFeedback, updateLanguageAndSendMenu, diff --git a/functions/src/definitions/eventHandlers/checkerHandlerTelegram.ts b/functions/src/definitions/eventHandlers/checkerHandlerTelegram.ts new file mode 100644 index 00000000..1a758e40 --- /dev/null +++ b/functions/src/definitions/eventHandlers/checkerHandlerTelegram.ts @@ -0,0 +1,55 @@ +//TODO TONGYING: Implement webhook here! +import * as admin from "firebase-admin" +import * as functions from "firebase-functions" + +import TelegramBot, { Update } from "node-telegram-bot-api" +import { onMessagePublished } from "firebase-functions/v2/pubsub" + +const TOKEN = String(process.env.TELEGRAM_CHECKER_BOT_TOKEN) +const bot = new TelegramBot(TOKEN) + +// More bot handlers can go here... + +// General message handler +bot.on("message", (msg) => { + if (msg.text && !msg.text.startsWith("/")) { + // Ignore commands as they are handled separately + const chatId = msg.chat.id + // Echo the message text back to the same chat + bot.sendMessage(chatId, `You said: ${msg.text}`) + } +}) + +const checkerHandlerTelegram = async function (body: Update) { + bot.processUpdate(body) + return +} + +const onCheckerPublishTelegram = onMessagePublished( + { + topic: "checkerEvents", + secrets: [ + "TYPESENSE_TOKEN", + "ML_SERVER_TOKEN", + "TELEGRAM_REPORT_BOT_TOKEN", + "TELEGRAM_CHECKER_BOT_TOKEN", + ], + }, + async (event) => { + if ( + event.data.message.json && + event.data.message.attributes.source === "telegram" + ) { + functions.logger.log(`Processing ${event.data.message.messageId}`) + await checkerHandlerTelegram(event.data.message.json) + } else { + if (!event.data.message.json) { + functions.logger.warn( + `Unknown message type for messageId ${event.data.message.messageId})` + ) + } + } + } +) + +export { onCheckerPublishTelegram } diff --git a/functions/src/definitions/eventHandlers/checkerHandlers.ts b/functions/src/definitions/eventHandlers/checkerHandlerWhatsapp.ts similarity index 98% rename from functions/src/definitions/eventHandlers/checkerHandlers.ts rename to functions/src/definitions/eventHandlers/checkerHandlerWhatsapp.ts index f5e0bc4e..0748763c 100644 --- a/functions/src/definitions/eventHandlers/checkerHandlers.ts +++ b/functions/src/definitions/eventHandlers/checkerHandlerWhatsapp.ts @@ -463,8 +463,10 @@ const onCheckerPublish = onMessagePublished( }, async (event) => { if (event.data.message.json) { - functions.logger.log(`Processing ${event.data.message.messageId}`) - await checkerHandlerWhatsapp(event.data.message.json) + if (event.data.message.attributes.source === "whatsapp") { + functions.logger.log(`Processing ${event.data.message.messageId}`) + await checkerHandlerWhatsapp(event.data.message.json) + } } else { functions.logger.warn( `Unknown message type for messageId ${event.data.message.messageId})` diff --git a/functions/src/definitions/eventHandlers/userHandlers.ts b/functions/src/definitions/eventHandlers/userHandlers.ts index a8b7da9b..fb8b19ed 100644 --- a/functions/src/definitions/eventHandlers/userHandlers.ts +++ b/functions/src/definitions/eventHandlers/userHandlers.ts @@ -20,7 +20,6 @@ import { sendInterimUpdate, sendVotingStats, sendReferralMessage, - respondToInterimFeedback, sendRationalisation, respondToRationalisationFeedback, updateLanguageAndSendMenu, @@ -401,7 +400,6 @@ async function newTextInstanceHandler({ isFrequentlyForwarded: isFrequentlyForwarded, //boolean, taken from webhook object isReplied: false, isInterimPromptSent: null, - isInterimUseful: null, isInterimReplySent: null, isMeaningfulInterimReplySent: null, isRationalisationSent: null, @@ -680,7 +678,6 @@ async function newImageInstanceHandler({ isFrequentlyForwarded: isFrequentlyForwarded, //boolean, taken from webhook object isReplied: false, isInterimPromptSent: null, - isInterimUseful: null, isInterimReplySent: null, isMeaningfulInterimReplySent: null, isRationalisationSent: null, @@ -753,10 +750,6 @@ async function onButtonReply(messageObj: Message, platform = "whatsapp") { ;[instancePath] = rest await sendInterimUpdate(instancePath) break - case "feedbackInterim": - ;[instancePath, selection] = rest - await respondToInterimFeedback(instancePath, selection) - break case "rationalisation": ;[instancePath] = rest await sendRationalisation(instancePath) diff --git a/functions/src/definitions/webhookHandlers/whatsapp.ts b/functions/src/definitions/webhookHandlers/handler.ts similarity index 84% rename from functions/src/definitions/webhookHandlers/whatsapp.ts rename to functions/src/definitions/webhookHandlers/handler.ts index 7b7b0455..5062051b 100644 --- a/functions/src/definitions/webhookHandlers/whatsapp.ts +++ b/functions/src/definitions/webhookHandlers/handler.ts @@ -10,7 +10,8 @@ import { Request, Response } from "express" const runtimeEnvironment = defineString("ENVIRONMENT") -const webhookPath = process.env.WEBHOOK_PATH +const webhookPathWhatsapp = process.env.WEBHOOK_PATH_WHATSAPP +const webhookPathTelegram = process.env.WEBHOOK_PATH_TELEGRAM const ingressSetting = process.env.ENVIRONMENT === "PROD" ? "ALLOW_INTERNAL_AND_GCLB" : "ALLOW_ALL" @@ -19,7 +20,7 @@ if (!admin.apps.length) { } const app = express() -const getHandler = async (req: Request, res: Response) => { +const getHandlerWhatsapp = async (req: Request, res: Response) => { /** * UPDATE YOUR VERIFY TOKEN *This will be the Verify Token value when you set up webhook @@ -46,7 +47,7 @@ const getHandler = async (req: Request, res: Response) => { } } -const postHandler = async (req: Request, res: Response) => { +const postHandlerWhatsapp = async (req: Request, res: Response) => { if (req.body.object) { if (req?.body?.entry?.[0]?.changes?.[0]?.value) { let value = req.body.entry[0].changes[0].value @@ -94,11 +95,11 @@ const postHandler = async (req: Request, res: Response) => { phoneNumberId === checkerPhoneNumberId ) { //put into checker queue - await publishToTopic("checkerEvents", message) + await publishToTopic("checkerEvents", message, "whatsapp") } if (phoneNumberId === userPhoneNumberId) { //put into user queue - await publishToTopic("userEvents", message) + await publishToTopic("userEvents", message, "whatsapp") } } res.sendStatus(200) @@ -141,15 +142,25 @@ const postHandler = async (req: Request, res: Response) => { } } +const postHandlerTelegram = async (req: Request, res: Response) => { + if ( + req.header("x-telegram-bot-api-secret-token") === + process.env.TELEGRAM_WEBHOOK_TOKEN + ) { + await publishToTopic("checkerEvents", req.body, "telegram") + } else { + functions.logger.warn( + "Telegram handler endpoint was called from unexpected source" + ) + } + res.sendStatus(200) +} + // Accepts POST requests at /{webhookPath} endpoint -app.post(`/${webhookPath}`, postHandler) -app.get(`/${webhookPath}`, getHandler) +app.post(`/${webhookPathWhatsapp}`, postHandlerWhatsapp) +app.get(`/${webhookPathWhatsapp}`, getHandlerWhatsapp) -app.post("/telegram", async (req, res) => { - const db = admin.firestore() - console.log(JSON.stringify(req.body)) - res.sendStatus(200) -}) +app.post(`/${webhookPathTelegram}`, postHandlerTelegram) // Accepts GET requests at the /webhook endpoint. You need this URL to setup webhook initially. // info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests @@ -163,6 +174,7 @@ const webhookHandlerV2 = onRequest( "VERIFY_TOKEN", "WHATSAPP_CHECKERS_WABA_ID", "WHATSAPP_USERS_WABA_ID", + "TELEGRAM_WEBHOOK_TOKEN", ], }, app diff --git a/functions/src/definitions/webhookHandlers/telegram.ts b/functions/src/definitions/webhookHandlers/telegram.ts deleted file mode 100644 index 60291b09..00000000 --- a/functions/src/definitions/webhookHandlers/telegram.ts +++ /dev/null @@ -1,31 +0,0 @@ -//TODO TONGYING: Implement webhook here! -import * as admin from "firebase-admin" -import * as functions from "firebase-functions" -import express from "express" -import TelegramBot from "node-telegram-bot-api" -import { onRequest } from "firebase-functions/v2/https" - -const TOKEN = String(process.env.TELEGRAM_CHECKER_BOT_TOKEN) -const bot = new TelegramBot(TOKEN) - -const app = express() - -bot.onText(/\/start/, (message) => { - bot.sendMessage(message.chat.id, "Welcome to the bot!") -}) - -// More bot handlers can go here... - -app.post("/", async (req, res) => { - bot.processUpdate(req.body) - res.sendStatus(200) -}) - -const telegramHandler = onRequest( - { - secrets: ["TELEGRAM_CHECKER_BOT_TOKEN"], - }, - app -) - -export { telegramHandler } diff --git a/functions/src/definitions/webhookHandlers/whatsappTest.ts b/functions/src/definitions/webhookHandlers/whatsappTest.ts index 1e841ed9..48e1d129 100644 --- a/functions/src/definitions/webhookHandlers/whatsappTest.ts +++ b/functions/src/definitions/webhookHandlers/whatsappTest.ts @@ -1,4 +1,4 @@ -import { app } from "./whatsapp" +import { app } from "./handler" import { agent } from "supertest" process.env.VERIFY_TOKEN = "testToken" diff --git a/functions/src/index.ts b/functions/src/index.ts index 5a3b12ee..601ec172 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -7,13 +7,13 @@ export { onInstanceCreate } from "./definitions/eventHandlers/onInstanceCreate" export { onInstanceDelete } from "./definitions/eventHandlers/onInstanceDelete" export { onInstanceUpdate } from "./definitions/eventHandlers/onInstanceUpdate" export { onMessageUpdate } from "./definitions/eventHandlers/onMessageUpdate" -export { webhookHandlerV2 } from "./definitions/webhookHandlers/whatsapp" +export { webhookHandlerV2 } from "./definitions/webhookHandlers/handler" export { onVoteRequestUpdate } from "./definitions/eventHandlers/onVoteRequestUpdate" export { healthcheck } from "./definitions/healthcheck" export { onMessageWrite } from "./definitions/eventHandlers/updateTypesense" export { onUserPublish } from "./definitions/eventHandlers/userHandlers" -export { onCheckerPublish } from "./definitions/eventHandlers/checkerHandlers" +export { onCheckerPublish } from "./definitions/eventHandlers/checkerHandlerWhatsapp" export { telegramAuthHandler } from "./definitions/api/authentication" -export { telegramHandler } from "./definitions/webhookHandlers/telegram" +export { onCheckerPublishTelegram } from "./definitions/eventHandlers/checkerHandlerTelegram" export { apiHandler } from "./definitions/api/api" export { batchJobs } diff --git a/integration-tests/checkmate.postman_collection.json b/integration-tests/checkmate.postman_collection.json index d8d70522..e89c4e58 100644 --- a/integration-tests/checkmate.postman_collection.json +++ b/integration-tests/checkmate.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "c96bcaae-e133-42b3-b840-ed90f0840413", + "_postman_id": "8ea99a98-6462-4c48-a8d0-ae5addd10b81", "name": "checkmate", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "_exporter_id": "25230076" @@ -97,7 +97,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -105,7 +105,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -215,7 +215,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -223,7 +223,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -334,7 +334,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -342,7 +342,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -467,7 +467,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -475,7 +475,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -599,7 +599,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -607,7 +607,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -716,7 +716,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -724,7 +724,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -835,7 +835,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -843,7 +843,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -973,7 +973,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -981,7 +981,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -1108,7 +1108,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -1116,7 +1116,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -1347,7 +1347,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -1355,7 +1355,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -1560,7 +1560,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -1568,7 +1568,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -1731,7 +1731,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -1739,7 +1739,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -2178,7 +2178,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -2186,7 +2186,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -2368,7 +2368,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -2376,7 +2376,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -2573,7 +2573,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -2581,7 +2581,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -2758,7 +2758,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -2766,7 +2766,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -2959,7 +2959,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -2967,14 +2967,14 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, "response": [] }, { - "name": "INTERIM_TEMPLATE_WITH_FEEDBACK", + "name": "INTERIM_TEMPLATE", "event": [ { "listen": "test", @@ -2987,12 +2987,10 @@ " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", " const INTERIM_TEMPLATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.en\");\r", - " const INTERIM_FEEDBACK = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.en\");\r", - " const BUTTON_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_USEFUL.en\");\r", - " const BUTTON_NOT_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_NOT_USEFUL.en\")\r", + " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\");\r", " const wamid = pm.variables.get(\"whatsapp_id_11\")\r", " const instanceId = pm.variables.get(\"spamInstanceId\")\r", - " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"spam🚧\").replace(\"{{info_placeholder}}\",\"\").replace(\"{{get_feedback}}\",INTERIM_FEEDBACK)\r", + " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"spam🚧\").replace(\"{{info_placeholder}}\",\"\")\r", " const expected = {\r", " \"hostname\": \"resultserver\",\r", " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", @@ -3011,288 +3009,6 @@ " {\r", " \"type\": \"reply\",\r", " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_yes`,\r", - " \"title\": BUTTON_USEFUL\r", - " }\r", - " },\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_no`,\r", - " \"title\": BUTTON_NOT_USEFUL\r", - " }\r", - " }\r", - " ]\r", - " }\r", - " },\r", - " \"context\": {\r", - " \"message_id\": wamid\r", - " }\r", - " },\r", - " \"method\": \"POST\"\r", - " }\r", - " var jsonData = pm.response.json();\r", - " \r", - " pm.expect(jsonData).to.eql(expected);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "setTimeout(() => {}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{RESULT_SERVER_URL}}/testresultdata", - "host": [ - "{{RESULT_SERVER_URL}}" - ], - "path": [ - "testresultdata" - ] - } - }, - "response": [] - }, - { - "name": "Press button \"Yes it's useful\"", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(200);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "// 1. Retrieve the current messageCounter and increment it.\r", - "let messageCounter = 14\r", - "\r", - "const whatsappId = \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFA1==\";\r", - "\r", - "// 3. Replace the last n characters (excluding the == at the end) of whatsappId with the new messageCounter\r", - "let n = messageCounter.toString().length;\r", - "let basePart = whatsappId.substring(0, whatsappId.length - n - 2);\r", - "let newId = basePart + messageCounter + \"==\";\r", - "\r", - "pm.collectionVariables.set(`whatsapp_id_${messageCounter}`, newId)\r", - "\r", - "// Allow time for firestore onUpdate event to complete\r" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"6580431949\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n {\r\n \"profile\": {\r\n \"name\": \"{{USER_1_NAME}}\"\r\n },\r\n \"wa_id\": \"{{USER_1_NUMBER}}\"\r\n }\r\n ],\r\n \"messages\": [\r\n {\r\n \"context\": {\r\n \"from\": \"6580431949\",\r\n \"id\": \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFAA==\"\r\n },\r\n \"from\": \"{{USER_1_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_14}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"type\": \"interactive\",\r\n \"interactive\": {\r\n \"type\": \"button_reply\",\r\n \"button_reply\": {\r\n \"id\": \"feedbackInterim_messages/{{spamMessageId}}/instances/{{spamInstanceId}}_yes\",\r\n \"title\": \"Yes, it's useful\"\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", - "host": [ - "{{FUNCTIONS_URL}}" - ], - "path": [ - "{{PROJECT_ID}}", - "asia-southeast1", - "webhookHandlerV2", - "{{WEBHOOK_PATH}}" - ] - } - }, - "response": [] - }, - { - "name": "INTERIM_USEFUL", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"INTERIM_USEFUL sent to user\", function () {\r", - " const CHECKER_PHONE_NUMBERS = [pm.variables.get(\"CHECKER_1_NUMBER\"), pm.variables.get(\"CHECKER_2_NUMBER\"), pm.variables.get(\"CHECKER_3_NUMBER\")]\r", - " const CHECKER_NAMES = [pm.variables.get(\"CHECKER_1_NAME\"), pm.variables.get(\"CHECKER_2_NAME\"), pm.variables.get(\"CHECKER_3_NAME\")]\r", - " const [, messageId, , voteRequestId] = pm.variables.get(\"spamVoteRequestPath_CHECKER1\").split(\"/\")\r", - " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", - " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", - " const INTERIM_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_USEFUL.en\");\r", - " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\")\r", - " const instanceId = pm.variables.get(\"spamInstanceId\")\r", - " const wamid = pm.variables.get(\"whatsapp_id_11\")\r", - " const expected = {\r", - " \"hostname\": \"resultserver\",\r", - " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", - " \"body\": {\r", - " \"messaging_product\": \"whatsapp\",\r", - " \"recipient_type\": \"individual\",\r", - " \"to\": USER_1_NUMBER,\r", - " \"type\": \"interactive\",\r", - " \"interactive\": {\r", - " \"type\": \"button\",\r", - " \"body\": {\r", - " \"text\": INTERIM_USEFUL\r", - " },\r", - " \"action\": {\r", - " \"buttons\": [\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", - " \"id\": `sendInterim_messages/${messageId}/instances/${instanceId}`,\r", - " \"title\": BUTTON_ANOTHER_UPDATE\r", - " }\r", - " }\r", - " ]\r", - " }\r", - " },\r", - " \"context\": {\r", - " \"message_id\": wamid\r", - " }\r", - " },\r", - " \"method\": \"POST\"\r", - " }\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData).to.eql(expected);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "setTimeout(() => {}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{RESULT_SERVER_URL}}/testresultdata", - "host": [ - "{{RESULT_SERVER_URL}}" - ], - "path": [ - "testresultdata" - ] - } - }, - "response": [] - }, - { - "name": "Press button \"No it's not\"", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(200);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "// Allow time for firestore onUpdate event to complete\r" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"6580431949\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n {\r\n \"profile\": {\r\n \"name\": \"{{USER_1_NAME}}\"\r\n },\r\n \"wa_id\": \"{{USER_1_NUMBER}}\"\r\n }\r\n ],\r\n \"messages\": [\r\n {\r\n \"context\": {\r\n \"from\": \"6580431949\",\r\n \"id\": \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFAA==\"\r\n },\r\n \"from\": \"{{USER_1_NUMBER}}\",\r\n \"id\": \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFAA==\",\r\n \"timestamp\": {{$timestamp}},\r\n \"type\": \"interactive\",\r\n \"interactive\": {\r\n \"type\": \"button_reply\",\r\n \"button_reply\": {\r\n \"id\": \"feedbackInterim_messages/{{spamMessageId}}/instances/{{spamInstanceId}}_no\",\r\n \"title\": \"No, it's not\"\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", - "host": [ - "{{FUNCTIONS_URL}}" - ], - "path": [ - "{{PROJECT_ID}}", - "asia-southeast1", - "webhookHandlerV2", - "{{WEBHOOK_PATH}}" - ] - } - }, - "response": [] - }, - { - "name": "INTERIM_NOT_USEFUL", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"INTERIM_NOT_USEFUL sent to user\", function () {\r", - " const CHECKER_PHONE_NUMBERS = [pm.variables.get(\"CHECKER_1_NUMBER\"), pm.variables.get(\"CHECKER_2_NUMBER\"), pm.variables.get(\"CHECKER_3_NUMBER\")]\r", - " const CHECKER_NAMES = [pm.variables.get(\"CHECKER_1_NAME\"), pm.variables.get(\"CHECKER_2_NAME\"), pm.variables.get(\"CHECKER_3_NAME\")]\r", - " const [, messageId, , voteRequestId] = pm.variables.get(\"spamVoteRequestPath_CHECKER1\").split(\"/\")\r", - " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", - " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", - " const INTERIM_NOT_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_NOT_USEFUL.en\");\r", - " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\")\r", - " const instanceId = pm.variables.get(\"spamInstanceId\")\r", - " const wamid = pm.variables.get(\"whatsapp_id_11\")\r", - " const expected = {\r", - " \"hostname\": \"resultserver\",\r", - " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", - " \"body\": {\r", - " \"messaging_product\": \"whatsapp\",\r", - " \"recipient_type\": \"individual\",\r", - " \"to\": USER_1_NUMBER,\r", - " \"type\": \"interactive\",\r", - " \"interactive\": {\r", - " \"type\": \"button\",\r", - " \"body\": {\r", - " \"text\": INTERIM_NOT_USEFUL\r", - " },\r", - " \"action\": {\r", - " \"buttons\": [\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", " \"id\": `sendInterim_messages/${messageId}/instances/${instanceId}`,\r", " \"title\": BUTTON_ANOTHER_UPDATE\r", " }\r", @@ -3307,6 +3023,7 @@ " \"method\": \"POST\"\r", " }\r", " var jsonData = pm.response.json();\r", + " \r", " pm.expect(jsonData).to.eql(expected);\r", "});" ], @@ -3387,7 +3104,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -3395,7 +3112,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -3415,7 +3132,6 @@ " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", " const INTERIM_TEMPLATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.en\");\r", - " const INTERIM_FEEDBACK = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.en\")\r", " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\")\r", " const instanceId = pm.variables.get(\"spamInstanceId\")\r", " const wamid = pm.variables.get(\"whatsapp_id_11\")\r", @@ -3517,7 +3233,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -3525,7 +3241,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -3707,7 +3423,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -3715,7 +3431,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -3912,7 +3628,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -3920,7 +3636,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -4093,7 +3809,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -4101,7 +3817,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -4221,7 +3937,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -4229,7 +3945,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -4411,7 +4127,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -4419,7 +4135,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -4616,7 +4332,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -4624,7 +4340,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -5012,7 +4728,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -5020,7 +4736,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -5181,7 +4897,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -5189,7 +4905,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -5308,7 +5024,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -5316,7 +5032,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -5349,7 +5065,6 @@ " },\r", " \"method\": \"POST\"\r", " }\r", - " console.log(JSON.stringify(expected,null,2))\r", " var jsonData = pm.response.json();\r", " pm.expect(jsonData).to.eql(expected);\r", "});" @@ -5441,7 +5156,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -5449,7 +5164,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -5887,7 +5602,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -5895,7 +5610,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -6082,7 +5797,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -6090,7 +5805,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -6311,7 +6026,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -6319,7 +6034,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -6453,7 +6168,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -6461,14 +6176,14 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, "response": [] }, { - "name": "INTERIM_TEMPLATE_WITH_FEEDBACK", + "name": "INTERIM_TEMPLATE", "event": [ { "listen": "test", @@ -6481,12 +6196,10 @@ " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", " const INTERIM_TEMPLATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.en\");\r", - " const INTERIM_FEEDBACK = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.en\");\r", - " const BUTTON_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_USEFUL.en\");\r", - " const BUTTON_NOT_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_NOT_USEFUL.en\")\r", + " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\")\r", " const instanceId = pm.variables.get(\"infoInstanceId\")\r", " const wamid = pm.variables.get(\"whatsapp_id_19\")\r", - " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"untrue❌\").replace(\"{{info_placeholder}}\",\", with an average score of 1.00 on a scale of 0-5 (5 = completely true)\").replace(\"{{get_feedback}}\",INTERIM_FEEDBACK)\r", + " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"untrue❌\").replace(\"{{info_placeholder}}\",\", with an average score of 1.00 on a scale of 0-5 (5 = completely true)\")\r", " const expected = {\r", " \"hostname\": \"resultserver\",\r", " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", @@ -6505,15 +6218,8 @@ " {\r", " \"type\": \"reply\",\r", " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_yes`,\r", - " \"title\": BUTTON_USEFUL\r", - " }\r", - " },\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_no`,\r", - " \"title\": BUTTON_NOT_USEFUL\r", + " \"id\": `sendInterim_messages/${messageId}/instances/${instanceId}`,\r", + " \"title\": BUTTON_ANOTHER_UPDATE\r", " }\r", " }\r", " ]\r", @@ -6557,55 +6263,6 @@ } }, "response": [] - }, - { - "name": "[DB CALL] Check interim values", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Check that instance interim data values are updated correctly\", function () {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData?.fields?.isMeaningfulInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimPromptSent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimUseful?.nullValue).to.equal(null);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Authorization", - "value": "Bearer owner", - "type": "text" - } - ], - "url": { - "raw": "{{FIRESTORE_URL}}/v1/projects/{{PROJECT_ID}}/databases/(default)/documents/messages/{{infoMessageId}}/instances/{{infoInstanceId}}", - "host": [ - "{{FIRESTORE_URL}}" - ], - "path": [ - "v1", - "projects", - "{{PROJECT_ID}}", - "databases", - "(default)", - "documents", - "messages", - "{{infoMessageId}}", - "instances", - "{{infoInstanceId}}" - ] - } - }, - "response": [] } ] }, @@ -6640,7 +6297,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -6648,7 +6305,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -6835,7 +6492,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -6843,7 +6500,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -7109,7 +6766,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -7117,7 +6774,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -7304,7 +6961,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -7312,7 +6969,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -7487,7 +7144,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -7495,7 +7152,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -7621,7 +7278,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -7629,7 +7286,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8067,7 +7724,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -8075,7 +7732,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8257,7 +7914,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -8265,7 +7922,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8461,7 +8118,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -8469,7 +8126,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8643,7 +8300,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -8651,7 +8308,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8843,7 +8500,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -8851,7 +8508,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -8906,53 +8563,19 @@ " },\r", " \"method\": \"POST\"\r", " }\r", - " var jsonData = pm.response.json();\r", - " \r", - " pm.expect(jsonData).to.eql(expected);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "setTimeout(() => {}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{RESULT_SERVER_URL}}/testresultdata", - "host": [ - "{{RESULT_SERVER_URL}}" - ], - "path": [ - "testresultdata" - ] - } - }, - "response": [] - }, - { - "name": "[DB CALL] Check interim values", - "event": [ + " var jsonData = pm.response.json();\r", + " \r", + " pm.expect(jsonData).to.eql(expected);\r", + "});" + ], + "type": "text/javascript" + } + }, { - "listen": "test", + "listen": "prerequest", "script": { "exec": [ - "pm.test(\"Check that instance interim data values are updated correctly\", function () {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData?.fields?.isMeaningfulInterimReplySent?.booleanValue).to.equal(false);\r", - " pm.expect(jsonData?.fields?.isInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimPromptSent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimUseful?.booleanValue).to.equal(false);\r", - "});" + "setTimeout(() => {}, 3000);" ], "type": "text/javascript" } @@ -8960,29 +8583,14 @@ ], "request": { "method": "GET", - "header": [ - { - "key": "Authorization", - "value": "Bearer owner", - "type": "text" - } - ], + "header": [], "url": { - "raw": "{{FIRESTORE_URL}}/v1/projects/{{PROJECT_ID}}/databases/(default)/documents/messages/{{unsureMessageId}}/instances/{{unsureInstanceId}}", + "raw": "{{RESULT_SERVER_URL}}/testresultdata", "host": [ - "{{FIRESTORE_URL}}" + "{{RESULT_SERVER_URL}}" ], "path": [ - "v1", - "projects", - "{{PROJECT_ID}}", - "databases", - "(default)", - "documents", - "messages", - "{{unsureMessageId}}", - "instances", - "{{unsureInstanceId}}" + "testresultdata" ] } }, @@ -9030,7 +8638,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -9038,7 +8646,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -9208,7 +8816,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -9216,14 +8824,14 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, "response": [] }, { - "name": "INTERIM_TEMPLATE_WITH_FEEDBACK", + "name": "INTERIM_TEMPLATE", "event": [ { "listen": "test", @@ -9237,211 +8845,9 @@ " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", " const wamid = pm.variables.get(\"whatsapp_id_23\")\r", " const INTERIM_TEMPLATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.en\");\r", - " const INTERIM_FEEDBACK = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.en\")\r", - " const BUTTON_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_USEFUL.en\");\r", - " const BUTTON_NOT_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_NOT_USEFUL.en\")\r", - " const instanceId = pm.variables.get(\"unsureInstanceId\")\r", - " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"legitimate✅\").replace(\"{{info_placeholder}}\",\"\").replace(\"{{get_feedback}}\",INTERIM_FEEDBACK)\r", - " const expected = {\r", - " \"hostname\": \"resultserver\",\r", - " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", - " \"body\": {\r", - " \"messaging_product\": \"whatsapp\",\r", - " \"recipient_type\": \"individual\",\r", - " \"to\": USER_1_NUMBER,\r", - " \"type\": \"interactive\",\r", - " \"interactive\": {\r", - " \"type\": \"button\",\r", - " \"body\": {\r", - " \"text\": interimResponse\r", - " },\r", - " \"action\": {\r", - " \"buttons\": [\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_yes`,\r", - " \"title\": BUTTON_USEFUL\r", - " }\r", - " },\r", - " {\r", - " \"type\": \"reply\",\r", - " \"reply\": {\r", - " \"id\": `feedbackInterim_messages/${messageId}/instances/${instanceId}_no`,\r", - " \"title\": BUTTON_NOT_USEFUL\r", - " }\r", - " }\r", - " ]\r", - " }\r", - " },\r", - " \"context\": {\r", - " \"message_id\": wamid\r", - " }\r", - " },\r", - " \"method\": \"POST\"\r", - " }\r", - " console.log(JSON.stringify(expected,null,2))\r", - " var jsonData = pm.response.json();\r", - " \r", - " pm.expect(jsonData).to.eql(expected);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "setTimeout(() => {}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{RESULT_SERVER_URL}}/testresultdata", - "host": [ - "{{RESULT_SERVER_URL}}" - ], - "path": [ - "testresultdata" - ] - } - }, - "response": [] - }, - { - "name": "[DB CALL] Check interim values", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Check that instance interim data values are updated correctly\", function () {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData?.fields?.isMeaningfulInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimPromptSent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimUseful?.booleanValue).to.equal(false);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Authorization", - "value": "Bearer owner", - "type": "text" - } - ], - "url": { - "raw": "{{FIRESTORE_URL}}/v1/projects/{{PROJECT_ID}}/databases/(default)/documents/messages/{{unsureMessageId}}/instances/{{unsureInstanceId}}", - "host": [ - "{{FIRESTORE_URL}}" - ], - "path": [ - "v1", - "projects", - "{{PROJECT_ID}}", - "databases", - "(default)", - "documents", - "messages", - "{{unsureMessageId}}", - "instances", - "{{unsureInstanceId}}" - ] - } - }, - "response": [] - }, - { - "name": "Press button \"Yes it's useful\"", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {\r", - " pm.response.to.have.status(200);\r", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "// 1. Retrieve the current messageCounter and increment it.\r", - "let messageCounter = 27\r", - "\r", - "const whatsappId = \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFA1==\";\r", - "\r", - "// 3. Replace the last n characters (excluding the == at the end) of whatsappId with the new messageCounter\r", - "let n = messageCounter.toString().length;\r", - "let basePart = whatsappId.substring(0, whatsappId.length - n - 2);\r", - "let newId = basePart + messageCounter + \"==\";\r", - "\r", - "pm.collectionVariables.set(`whatsapp_id_${messageCounter}`, newId)\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"6580431949\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n {\r\n \"profile\": {\r\n \"name\": \"{{USER_1_NAME}}\"\r\n },\r\n \"wa_id\": \"{{USER_1_NUMBER}}\"\r\n }\r\n ],\r\n \"messages\": [\r\n {\r\n \"context\": {\r\n \"from\": \"6580431949\",\r\n \"id\": \"wamid.HBgKNjU5Njg4MDMyMBUCABIYIEY4MDAwNTlEODQyMDZDMkNDOEU1NEVEQjc1MTNCMjlFAA==\"\r\n },\r\n \"from\": \"{{USER_1_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_27}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"type\": \"interactive\",\r\n \"interactive\": {\r\n \"type\": \"button_reply\",\r\n \"button_reply\": {\r\n \"id\": \"feedbackInterim_messages/{{unsureMessageId}}/instances/{{unsureInstanceId}}_yes\",\r\n \"title\": \"Yes, it's useful\"\r\n }\r\n }\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", - "host": [ - "{{FUNCTIONS_URL}}" - ], - "path": [ - "{{PROJECT_ID}}", - "asia-southeast1", - "webhookHandlerV2", - "{{WEBHOOK_PATH}}" - ] - } - }, - "response": [] - }, - { - "name": "INTERIM_USEFUL", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"INTERIM_USEFUL sent to user\", function () {\r", - " const CHECKER_PHONE_NUMBERS = [pm.variables.get(\"CHECKER_1_NUMBER\"), pm.variables.get(\"CHECKER_2_NUMBER\"), pm.variables.get(\"CHECKER_3_NUMBER\")]\r", - " const CHECKER_NAMES = [pm.variables.get(\"CHECKER_1_NAME\"), pm.variables.get(\"CHECKER_2_NAME\"), pm.variables.get(\"CHECKER_3_NAME\")]\r", - " const [, messageId, , voteRequestId] = pm.variables.get(\"unsureVoteRequestPath_CHECKER1\").split(\"/\")\r", - " const USER_1_NAME = pm.variables.get(\"USER_1_NAME\")\r", - " const USER_1_NUMBER = pm.variables.get(\"USER_1_NUMBER\")\r", - " const wamid = pm.variables.get(\"whatsapp_id_23\")\r", - " const INTERIM_USEFUL = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_USEFUL.en\");\r", " const BUTTON_ANOTHER_UPDATE = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.BUTTON_ANOTHER_UPDATE.en\")\r", " const instanceId = pm.variables.get(\"unsureInstanceId\")\r", + " const interimResponse = INTERIM_TEMPLATE.replace(\"{{%voted}}\", \"33.33\").replace(\"{{prelim_assessment}}\",\"legitimate✅\").replace(\"{{info_placeholder}}\",\"\")\r", " const expected = {\r", " \"hostname\": \"resultserver\",\r", " \"path\": \"/v15.0/WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID/messages\",\r", @@ -9453,7 +8859,7 @@ " \"interactive\": {\r", " \"type\": \"button\",\r", " \"body\": {\r", - " \"text\": INTERIM_USEFUL\r", + " \"text\": interimResponse\r", " },\r", " \"action\": {\r", " \"buttons\": [\r", @@ -9474,6 +8880,7 @@ " \"method\": \"POST\"\r", " }\r", " var jsonData = pm.response.json();\r", + " \r", " pm.expect(jsonData).to.eql(expected);\r", "});" ], @@ -9504,55 +8911,6 @@ } }, "response": [] - }, - { - "name": "[DB CALL] Check interim values", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Check that instance interim data values are updated correctly\", function () {\r", - " var jsonData = pm.response.json();\r", - " pm.expect(jsonData?.fields?.isMeaningfulInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimReplySent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimPromptSent?.booleanValue).to.equal(true);\r", - " pm.expect(jsonData?.fields?.isInterimUseful?.booleanValue).to.equal(true);\r", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Authorization", - "value": "Bearer owner", - "type": "text" - } - ], - "url": { - "raw": "{{FIRESTORE_URL}}/v1/projects/{{PROJECT_ID}}/databases/(default)/documents/messages/{{unsureMessageId}}/instances/{{unsureInstanceId}}", - "host": [ - "{{FIRESTORE_URL}}" - ], - "path": [ - "v1", - "projects", - "{{PROJECT_ID}}", - "databases", - "(default)", - "documents", - "messages", - "{{unsureMessageId}}", - "instances", - "{{unsureInstanceId}}" - ] - } - }, - "response": [] } ] }, @@ -9587,7 +8945,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -9595,7 +8953,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -9777,7 +9135,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -9785,7 +9143,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -9979,7 +9337,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -9987,7 +9345,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -10157,7 +9515,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -10165,7 +9523,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -10288,7 +9646,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -10296,7 +9654,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -10417,7 +9775,6 @@ " },\r", " \"method\": \"POST\"\r", " }\r", - " //console.log(JSON.stringify(expected,null,2))\r", " var jsonData = pm.response.json();\r", " pm.expect(jsonData).to.eql(expected);\r", "});" @@ -10478,7 +9835,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -10486,7 +9843,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -10682,7 +10039,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -10690,7 +10047,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -10976,7 +10333,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -10984,7 +10341,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11104,7 +10461,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11112,7 +10469,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11290,7 +10647,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11298,7 +10655,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11408,7 +10765,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11416,7 +10773,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11526,7 +10883,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11534,7 +10891,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11644,7 +11001,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11652,7 +11009,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11762,7 +11119,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11770,7 +11127,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -11897,7 +11254,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -11905,7 +11262,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12083,7 +11440,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12091,7 +11448,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12263,7 +11620,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12271,7 +11628,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12387,7 +11744,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12395,7 +11752,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12559,7 +11916,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12567,7 +11924,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12662,8 +12019,6 @@ " \"menu_dispute\",\r", " \"text_machine_unsure\",\r", " \"sendInterim\",\r", - " \"feedbackInterim_yes\",\r", - " \"feedbackInterim_no\",\r", " \"sendInterim\",\r", " \"sendInterim\",\r", " \"satisfactionSurvey_10\",\r", @@ -12675,7 +12030,6 @@ " \"text_machine_unsure\",\r", " \"sendInterim\",\r", " \"sendInterim\",\r", - " \"feedbackInterim_yes\",\r", " \"sendInterim\",\r", " \"votingResults\",\r", " \"text_menu\",\r", @@ -12759,6 +12113,11 @@ "let newId = basePart + messageCounter + \"==\";\r", "\r", "pm.collectionVariables.set(`whatsapp_id_${messageCounter}`, newId)\r", + "\r", + "// Get the variable that contains new lines\r", + "let responseBody = pm.variables.get(\"__CONSTANTS__.USER_BOT_RESPONSES.REFERRAL_PREPOPULATED_PREFIX.en\");\r", + "// Escape new lines and set it to a new variable\r", + "pm.variables.set(\"escapedPrepopulatedPrefix\", responseBody.replace(/(\\r\\n|\\n|\\r)/gm, \"\\\\n\"));\r", "" ], "type": "text/javascript" @@ -12770,7 +12129,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"15550933685\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n { \"profile\": { \"name\": \"{{USER_2_NAME}}\" }, \"wa_id\": \"{{USER_2_NUMBER}}\" }\r\n ],\r\n \"messages\": [\r\n {\r\n \"from\": \"{{USER_2_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_39}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"text\": { \"body\": \"{{__CONSTANTS__.USER_BOT_RESPONSES.REFERRAL_PREPOPULATED_PREFIX.en}} {{referralId_USER1}}\" },\r\n \"type\": \"text\"\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}\r\n", + "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"15550933685\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n { \"profile\": { \"name\": \"{{USER_2_NAME}}\" }, \"wa_id\": \"{{USER_2_NUMBER}}\" }\r\n ],\r\n \"messages\": [\r\n {\r\n \"from\": \"{{USER_2_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_39}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"text\": { \"body\": \"{{escapedPrepopulatedPrefix}} {{referralId_USER1}}\" },\r\n \"type\": \"text\"\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}\r\n", "options": { "raw": { "language": "json" @@ -12778,7 +12137,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12786,7 +12145,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -12913,7 +12272,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -12921,7 +12280,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -13137,7 +12496,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"15550933685\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n { \"profile\": { \"name\": \"{{USER_2_NAME}}\" }, \"wa_id\": \"{{USER_2_NUMBER}}\" }\r\n ],\r\n \"messages\": [\r\n {\r\n \"from\": \"{{USER_2_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_40}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"text\": { \"body\": \"{{__CONSTANTS__.USER_BOT_RESPONSES.REFERRAL_PREPOPULATED_PREFIX.en}} {{referralId_USER1}}\" },\r\n \"type\": \"text\"\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}\r\n", + "raw": "{\r\n \"object\": \"whatsapp_business_account\",\r\n \"entry\": [\r\n {\r\n \"id\": \"WHATSAPP_TEST_USER_WABA_ID\",\r\n \"changes\": [\r\n {\r\n \"value\": {\r\n \"messaging_product\": \"whatsapp\",\r\n \"metadata\": {\r\n \"display_phone_number\": \"15550933685\",\r\n \"phone_number_id\": \"WHATSAPP_TEST_USER_BOT_PHONE_NUMBER_ID\"\r\n },\r\n \"contacts\": [\r\n { \"profile\": { \"name\": \"{{USER_2_NAME}}\" }, \"wa_id\": \"{{USER_2_NUMBER}}\" }\r\n ],\r\n \"messages\": [\r\n {\r\n \"from\": \"{{USER_2_NUMBER}}\",\r\n \"id\": \"{{whatsapp_id_40}}\",\r\n \"timestamp\": {{$timestamp}},\r\n \"text\": { \"body\": \"{{escapedPrepopulatedPrefix}} {{referralId_USER1}}\" },\r\n \"type\": \"text\"\r\n }\r\n ]\r\n },\r\n \"field\": \"messages\"\r\n }\r\n ]\r\n }\r\n ]\r\n}\r\n", "options": { "raw": { "language": "json" @@ -13145,7 +12504,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -13153,7 +12512,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -13348,7 +12707,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -13356,7 +12715,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -13509,7 +12868,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -13517,7 +12876,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, @@ -13560,7 +12919,7 @@ } }, "url": { - "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH}}", + "raw": "{{FUNCTIONS_URL}}/{{PROJECT_ID}}/asia-southeast1/webhookHandlerV2/{{WEBHOOK_PATH_WHATSAPP}}", "host": [ "{{FUNCTIONS_URL}}" ], @@ -13568,7 +12927,7 @@ "{{PROJECT_ID}}", "asia-southeast1", "webhookHandlerV2", - "{{WEBHOOK_PATH}}" + "{{WEBHOOK_PATH_WHATSAPP}}" ] } }, diff --git a/integration-tests/env.json b/integration-tests/env.json index 091aa869..3921b826 100644 --- a/integration-tests/env.json +++ b/integration-tests/env.json @@ -19,10 +19,15 @@ "enabled": true }, { - "key": "WEBHOOK_PATH", + "key": "WEBHOOK_PATH_WHATSAPP", "value": "whatsapp", "enabled": true }, + { + "key": "WEBHOOK_PATH_TELEGRAM", + "value": "telegram", + "enabled": true + }, { "key": "FIRESTORE_URL", "value": "http://localhost:18080", @@ -190,7 +195,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.ERROR.cn", - "value": "抱歉,查友在评估您提供的短信时发生问题。\n\n欢迎您稍后重试,或者通过这份表格向我们反馈:https://bit.ly/checkmate-feedback。对此造成的不便,我们非常抱歉!😔", + "value": "抱歉,查友在评估您提供的短信时发生了问题。\n\n欢迎您稍后重试,或者通过这份表格向我们反馈:https://bit.ly/checkmate-feedback。对此造成的不便,我们非常抱歉!😔", "enabled": true }, { @@ -230,7 +235,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.SPAM.cn", - "value": "{{thanks}}{{matched}}{{methodology}}是垃圾信息!🚧{{image_caveat}}\n\n虽然它看似无害,但仍然请您保持警惕 🧐\n\n感谢您对新加坡网络安全的支持和贡献!", + "value": "{{thanks}}{{matched}}{{methodology}}是垃圾信息!🚧{{image_caveat}}\n\n虽然它看似无害,但请仍然保持警惕 🧐\n\n感谢您对新加坡网络安全的支持和贡献!", "enabled": true }, { @@ -315,12 +320,12 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.en", - "value": "At this time, {{%voted}}% of our CheckMates have assessed and voted on this message. The majority think that this is {{prelim_assessment}}{{info_placeholder}}. \n\nNOTE: This is a *preliminary result*. We aim to provide you with a more credible final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.{{get_feedback}}", + "value": "At this time, {{%voted}}% of our CheckMates have assessed and voted on this message. The majority think that this is {{prelim_assessment}}{{info_placeholder}}. \n\nNOTE: This is a *preliminary result*. We aim to provide you with a more credible final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.", "enabled": true }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE.cn", - "value": "目前,{{%voted}}%的查哥查妹已经对这条短信进行投票评估。大多数人认为这条短信{{prelim_assessment}}{{info_placeholder}}。\n\n注意:这只是初步结果。我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。{{get_feedback}}", + "value": "目前,{{%voted}}%的查哥查妹已经对这条短信进行投票评估。大多数人认为这条短信{{prelim_assessment}}{{info_placeholder}}。\n\n注意:这只是初步结果。我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。", "enabled": true }, { @@ -330,17 +335,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_TEMPLATE_UNSURE.cn", - "value": "目前,{%voted}}%的查哥查妹已经对这条短信进行投票评估。不幸的是,他们无法达成一致,或缺乏足够的信息进行评估。\n\n如果您能提供更多信息,例如发信人电话号码或截图,将有助于我们更好地评估。", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.en", - "value": "\n\nThanks for trusting CheckMate! 👋🏼 If this interim update was useful to you, we'd appreciate it if you'd let us know by tapping on “Yes, it's useful” below. Otherwise, tap on “No, it's not” to continue waiting for the final result. Either way, you can continue to request more updates as more votes come in.", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_FEEDBACK.cn", - "value": "感谢您对查友的信任!👋🏼 如果这个初步结果对您有帮助,请点击“有帮助”。否则,请点击“没帮助”以继续等待最终结果。您可以在最终结果发布之前随时要求最新的初步结果。", + "value": "目前,{%voted}}%的查哥查妹已经对这条短信进行投票评估。但是,他们无法达成一致,或缺乏足够的信息进行评估。\n\n如果您能提供更多信息,例如发信人电话号码或截图,将有助于我们更好地评估。", "enabled": true }, { @@ -350,27 +345,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_PROMPT.cn", - "value": "感谢您的耐心等待!查哥查妹正在对您提交的短信进行投票评估。我们将在足够多的查哥查妹票后,为您提供最终结果。\n\n在最终结果发布之前,您可以点击获取初步结果。请注意,初步结果和最终结果之间可能存在差异,应谨慎解读初步结果。我们感谢您的耐心,并希望尽快为您提供最终结果!💪🏼", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_USEFUL.en", - "value": "Thanks for your valuable feedback! We will provide you with the final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.\n\nIn the meantime, if you'd like another update after more votes come in, just tap the button below to request one.", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_USEFUL.cn", - "value": "感谢您的反馈!我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,为您提供最终的结果。\n\n请点击下方按钮再次获取最新的初步结果。", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_NOT_USEFUL.en", - "value": "Sorry to hear that, but thanks anyway for your valuable feedback! We will provide you with the final result as soon as more of our CheckMates have voted, or when 24 hours has lapsed since you sent in your message.\n\nIf you'd like still another update after more votes come in, just tap the button below to request one.", - "enabled": true - }, - { - "key": "__CONSTANTS__.USER_BOT_RESPONSES.INTERIM_NOT_USEFUL.cn", - "value": "感谢您的反馈!我们将在更多的查哥查妹投票后,或在您提交短信的24小时内,尽快为您提供最终的结果。\n\n请点击下方按钮再次获取最新的初步结果。", + "value": "感谢您的耐心等待!查哥查妹正在对您提交的短信进行投票评估。我们将在足够多的查哥查妹票后,为您提供最终结果。\n\n在最终结果发布之前,您可以点击“获取初步结果”。请注意,初步结果和最终结果可能存在差异,应谨慎解读初步结果。我们感谢您的耐心,并会尽快提供最终结果!💪🏼", "enabled": true }, { @@ -440,7 +415,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.PROCEED_TO_SEND.cn", - "value": "好的!您只需将短信发送给查友,我们会对其进行评估!✅✅\n\n除了文字信息,您也可以发送截图📷或其他图片🖼️!这有助于查哥查妹通过发信人号码或完整的对话内容做出判断。\n\n最后,使用查友即表示您已同意我们的隐私政策。您可在 https://checkmate.sg/privacy-policy 查看我们的隐私政策。基本上,我们只收集您发送的消息以及您的手机号码,以便回复您!", + "value": "好的!您只需将短信发送给查友,我们会对此进行评估!✅✅\n\n除了文字信息,您也可以发送截图📷或其他图片🖼️!这有助于查哥查妹通过发信人号码或完整的对话内容做出评判。\n\n最后,使用查友即表示您已同意我们的隐私政策。您可在 https://checkmate.sg/privacy-policy 查看我们的隐私政策。基本上,我们只收集您发送的消息以及您的手机号码,以便回复您!", "enabled": true }, { @@ -505,22 +480,22 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.REFERRAL_PREPOPULATED_PREFIX.en", - "value": "Welcome to CheckMate! Send in this entire message (including the code) to get started, and credit your friend with your referral. Code:", + "value": "Welcome to CheckMate! Send in this message to get started, and credit your friend with your referral.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", "enabled": true }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.REFERRAL_PREPOPULATED_PREFIX.cn", - "value": "欢迎使用查友!请发送这条短信(包括推荐人代码)以开始使用。代码:", + "value": "Welcome to CheckMate! Send in this message to get started, and credit your friend with your referral.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", "enabled": true }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.GENERIC_PREPOPULATED_PREFIX.en", - "value": "Welcome to Checkmate! Send in this entire message (including the code) to get started. Code:", + "value": "Welcome to CheckMate! Send in this message to get started.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", "enabled": true }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.GENERIC_PREPOPULATED_PREFIX.cn", - "value": "欢迎使用查友!请发送这条短信(包括代码)以开始使用。代码:", + "value": "Welcome to CheckMate! Send in this message to get started.\n\n欢迎使用查友!请发送这条短信以开始使用。\n\nCode:", "enabled": true }, { @@ -960,7 +935,7 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.MENU.cn", - "value": "{{prefix}}\n\n请点击“菜单\"查看查友的功能!👈\n\n请注意,查友仅能评估您发送的短信,它无法与您进行对话。\n\n您只需输入\"菜单\"即可随时返回这里,查看查友的功能!😊", + "value": "{{prefix}}\n\n请点击“菜单\"查看查友的功能!👈\n\n请注意,查友只评估您发送的短信,它无法与您进行对话。\n\n您只需输入\"菜单\"即可随时返回这里,查看查友的功能!😊", "enabled": true }, { @@ -985,12 +960,12 @@ }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.NEW_USER_PREFIX_CN.en", - "value": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n", + "value": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n\n", "enabled": true }, { "key": "__CONSTANTS__.USER_BOT_RESPONSES.NEW_USER_PREFIX_CN.cn", - "value": "您好,欢迎使用查友!很高兴您加入我们,一起参与反击诈骗和虚假信息😊。", + "value": "您好,欢迎来到查友!我们很高兴您加入我们,一起对抗诈骗和误导信息😊。\n\n", "enabled": true }, { diff --git a/package.json b/package.json index 05c1b5e5..be4fb26d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,6 @@ "scripts": { "lint": "eslint . --ext js,jsx,ts,tsx --fix", "postinstall": "cd functions && npm install && cd ../checkers-app && npm install", - "serve": "firebase emulators:start --import ./local-data --export-on-exit ./local-data" + "serve": "firebase emulators:start --project checkmate-uat --import ./local-data --export-on-exit ./local-data" } }