Apply Opt-in Flow to Chatbot
Opt-in is a very important safeguard for enterprise, especially when the brand is running a marketing campaign with prizes. In most cases, users will need to opt-in or agree to a set of terms & conditions. A well-written terms will clear any disputes originated from the chatbot game because it set the expectation, rules & regulations for players or users.
Another important use case is to send WhatsApp Template Message from WABA to users. The rules state that a business must get the consent from their users before sending any push messages. For details, you may refer to the opt-in requirement in WhatsApp Overview.
These use cases require an opt-in conversation flow, a record of the opt-in user data, as well as a way to filter out who is opted-in in our member page & push panel.
The following object(s) and method(s) will be used in the application of data source:
Expected Outcome
There are 4 types of expected outcome:
- User agrees on the terms of service and redirected to the starting message of the chatbot service. At the same time, the user is tagged with "Agree TNC" and also has a record on the Opt-in Record data source.
- Any users who accepted the T&C previously would not be asked to agree to the terms of service the next time they greet the chatbot.
- User disagrees on the terms of service and redirected back to the T&C message.
- User types something randomly to trigger the fail safe and redirected back to the T&C message.
Sample Chatbot Structure
Create a General Node - TNC
Enter the Bot Builder here to create your node.
Create a General Node and rename it as "TNC".
Create a Response for stating the terms of service and define what constitutes as agreement to the T&C.
- Save the Node.
Create a Data Source - Opt-in Record
- Create a new data source.
- Import this sample Opt-in Record to the Data Source.
- Copy the Data Source ID.
Create a General Node - TNC Agree
Create a General Node and rename it as "TNC Agree".
Create a Trigger for detecting keywords that constitutes as agreement.
- Create the 1st Pre-action for setting the status of user agreeing to T&C in the member data. Rename it as "Set User Agree TNC Status". You may refer to the following code:
return new Promise((resolve) => {
this.lodash.set(this.member, "tags", this.lodash.get(this.member, "tags", []).filter(tag => tag !== "Disagree TNC"))
this.lodash.set(this.member, "botMeta.tempData.userAgreeTNC", true)
resolve({
member: this.member
})
})
tip
Please make sure the tag in the array (i.e. Disagree TNC) is the same as the one set in Create a Node - TNC Disagree.
- Create the 2nd Pre-action for upserting the user opt-in record to the Data Source. You may refer to the following code:
return new Promise(async(resolve) => {
await this.upsertDataToDataSource({
dataSourceId: "Insert Data Source ID Here",
data: {
"Member ID": this.member._id,
"Name": this.member.firstName,
"Whatsapp Number": this.member.externalId,
"Opt-in": "Y"
}
})
resolve({
member: this.member
})
})
tip
Please remember to set the dataSourceId with the Data Source ID you created for Opt-in Record. You can change the data's naming (i.e. the array of data
, e.g. "Member ID") to fit your Data Source column headers too.
- Create a response for stating to users that the opt-in has been completed.
- You may choose to toggle on "Redirect" back to the start of chatbot service, so that user can continue the conversation seamlessly.
- Toggle on "Member Tagging" and set the tag as "Agree TNC".
- Save the Node.
Create a General Node - TNC Disagree
- Create a General Node and rename it as "TNC Disagree".
- Create a Trigger for detecting keywords that constitutes as disagreement.
- Create a response for stating to users that the opt-in has failed.
- You may choose to toggle on "Redirect" back to the start of the opt-in flow, so that user can decide for the second time.
- Toggle on "Member Tagging" and set the tag as "Disagree TNC".
- Save the Node.
Create a General Node - TNC failsafe
Create a General Node and rename it as "TNC failsafe".
Create a Trigger for any text, any payload or any media. Rename the Trigger as "Type all".
- Create a response for stating to users that the chatbot does not comprehend user's input.
- Toggle on "Redirect" back to the start of the opt-in flow, so that user can input for the second time.
- Save the Node.
Create a Global Node - Greetings Keywords
Create a Global Node and rename it as "Greetings Keywords". This Global Node is to determine if the user has opted-in before. If the member tag "Agree TNC" is present, it means the user has opted in and then the system will redirect user to the start of chatbot service. Otherwise, the system will redirect user to the Node - "TNC".
Create a Trigger for detecting greetings keywords. Rename the Trigger as "Text: Greetings".
- Toggle on "Redirect" and copy the following code to the "Advanced" tab:
return new Promise (resolve => {
const memberTagArray = this.lodash.get(this.member, "tags", [])
if (memberTagArray.includes("Agree TNC")) {
resolve({
tree: "Insert Chatbot ID here or this.node.tree", // Chatbot ID of the start of chatbot service
nodeCompositeId: "Insert Node Composite ID Here", // Node Composite ID of the start of chatbot service
runPreAction: true,
sendResponse: true,
runPostAction: true,
})
}
resolve({
tree: this.node.tree,
nodeCompositeId: "Insert Node Composite ID Here", // Node Composite ID of TNC
runPreAction: true,
sendResponse: true,
runPostAction: true,
})
})
tip
For this section, you may set which Node the chatbot should redirect to. Insert a Chatbot ID if it is not in the same Opt-in Flow. Otherwise, type this.node.tree
.
- Save the Global Node and see if you can produce the expected outcome.