Skip to main content

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.

Transformer Node

Expected Outcome

The same response related to sports can be sent when user answers different kind of sports.

Transformer Node

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.

Transformer Node

Create General Node for First Question

  1. First, create a general node for displaying the key question.

Create Response

  1. Create a response.
  1. Create the text response and ask the user to type their answers.

Create Transformer Node

  1. Create a transformer node following the first node.
  1. This node is for transforming user's input into one response.

Add keywords trigger

  1. Create a trigger, add a list of keywords related to sports.

Add Actions to transform response

  1. In the transformer node, create an action.
  1. 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

  1. Create a new general node (tree node) for displaying the follow-up response.

Add Trigger

  1. Create a keyword trigger. The keyword should match with the modified response in the transformer node.

Add Response

  1. Create a response to fit this scenario.

Create Global Node as Entry

  1. Create a global node.
  1. This global node is for providing an entry point to this chatbot.
  1. Create a new trigger for greeting keywords.
  1. Switch on "Redirect" and link back to the first question.

Add Chatbot to Channel

  1. Finally, add this chatbot to your channel and you should be able to test the outcome!