Apply Transformer Node to Chatbot
Introduction
The Transformer Node is a category of node, alongside with General Node and Global Node.
Unlike a general node, a Transformer Node is not responsible for sending out message to the end user. Instead, it allows you to transform and modify the incoming event. After that, the processed event can enter the node matching again and be able to trigger the child node. This unique feature enables the use of NLP tools in your chatbot, such as Dialogflow.
In this section, we will build a simple chatbot to demonstrate how could the transformer node modify an event and pass it on to the child node.
Expected Outcome
The same response related to sports can be sent when user answers different kind of sports.
Sample Chatbot Structure
In this simple example, we will ask the user to enter their favorite sports. Then, the transformer node will recognize the keywords and modify them into the same keyword: "sports", in order to trigger the response designed for sporty users.
Create General Node for First Question
- First, create a general node for displaying the key question.
Create Response
- Create a response.
- Create the text response and ask the user to type their answers.
Create Transformer Node
- Create a transformer node following the first node.
- This node is for transforming user's input into one response.
Add keywords trigger
- Create a trigger, add a list of keywords related to sports.
Add Actions to transform response
- In the transformer node, create an action.
- Select "Advanced", and apply the following code. This function could transform the text input into a new response.
return new Promise((resolve) => {
this.lodash.set(this.messageEvent, "data.text", "sports")
resolve({
messageEvent: this.messageEvent
})
})
Create General Node for Follow-up Response
- Create a new general node (tree node) for displaying the follow-up response.
Add Trigger
- Create a keyword trigger. The keyword should match with the modified response in the transformer node.
Add Response
- Create a response to fit this scenario.
Create Global Node as Entry
- Create a global node.
- This global node is for providing an entry point to this chatbot.
- Create a new trigger for greeting keywords.
- Switch on "Redirect" and link back to the first question.
Add Chatbot to Channel
- Finally, add this chatbot to your channel and you should be able to test the outcome!