Two simple chatbots. Let’s call them ‘Red’ and ‘Blue’. What’s special about them is they allow the user to talk to either of them and swap between them.
You may be thinking, why have two? When one seems so much simpler? Well, by creating two separate bots on two different services that can interact with each other, the user gets the best possible experience by being able to maximize the quality of the information they receive. It creates flexibility for the customer as well as moving away from outdated linear ideas, and instead creating a network.
This article will take you through 5 easy-to-follow steps to create your own two bots in Zwerm.
Your objective is to create two separate bots, each using a different language processor, that can interact with each other. The ‘Blue’ bot will talk about all things blue, while the ‘Red’ bot talks about all things red. This is obviously just for demonstration purposes. You can fill in situations like a user talking to your operations department and requesting a financial statement in the process or having a temporary marketing campaign in your conversational user interface. The user will be able to talk to the bot, and if they wish to
speak with another bot who has more expertise in a certain area, the transfer between the bots will happen.
Following the completion of this tutorial, you will be able to:
- Create a bot called “Blue bot” on DialogFlow
- Create a bot on Amazon Lex called “Red bot”
- Set them both up as one single bot in Zwerm and any channel we support
- Use events and custom fulfilment to let the user choose which bot they want to talk to
Before you can begin building the examples of Red and Blue, you will need the following:
Step 1: How to build Blue on DialogFlow
Firstly, download the Blue bot archive we have prepared for you, to easily import into DialogFlow.
Once you’re in the DialogFlow Console, open the agent list drop-down menu in the left navigation. Select ‘Create New Agent’ at the bottom. In the form, enter ‘demo-blue’ as agent name, select ‘English -en’ as Default Language (this is often pre-selected) and then choose a default timezone. Either create a new Google Project or choose an existing one. Click create in the top right corner to continue.
Once the agent has been created, you will be taken to a list of intents. Ignore these for now, and select the settings symbol, then select the ‘Export and Import’ tab. Select ‘Restore from Zip’ and choose the archive provided. Type restore in the text field and click the Restore button to confirm the import.
Lastly, follow DialogFlow’s guide to retrieve your authentication key and keep it safe. You will need it later to set up the agent with Zwerm.
Step 2: How to build Red on Amazon Lex
First, download the Red bot archive we have prepared for easy import into Amazon Lex.
Open the AWS Console and navigate to the Amazon Lex Service home. Select ‘Actions’ and ‘Import’. In the pop-up dialog, open the file you’ve just downloaded and click ‘Import’ again.
(Note: In Amazon Lex you cannot have multiple bots of intents with the same name. If you get a conflict while importing, Lex will ask you what to do. In that case, we recommend you unpack the archive manually and edit the JSON file to avoid duplicate names before importing.)
Next, click on the name of the bot in the list to open it. In the top right corner, select ‘Build’ and confirm in the dialog. This may take a while but should build your bot without any errors. Once you have confirmation of the success, you can test your bot out on the right side of the screen.
For now, skip this step and select ‘Publish’ next to the build button. In the dialog window, enter ‘demo’ as an alias name and click ‘Publish’ to continue. After a few minutes, this will be finished.
Before you’re ready for the next step, write down the following things:
- The name of your Lex bot (‘Red’)
- The alias (‘demo’)
- The region (‘us-west-2’)
You will need these later on. You will also need to create an IAM Access key and secret. Follow our guide for Amazon LEX to create them.
Step 3: Connecting your two bots to Zwerm
Now that Red and Blue are ready to go, you can now connect them to Zwerm.
Open the Zwerm IAM Console and select ‘Add a bot’ on your dashboard. If you haven’t set up a team yet, you will have to create one first.
The ‘Create new bot’ will open, so enter ‘RedBlue’ as the bot name and the bot ID will be filled in automatically. Select ‘DialogFlow’ as the engine and set it to API Version V2. Choose and upload the authentication key file you created in Step 1 and give it the label ‘Blue’. Click Create and you will be taken to the overview page of your bots. Click the bot name.
Next, you will need to connect your Red bot. In the settings on the left, select ‘Engines’. Choose ‘Amazon Lex’ in the drop-down list and select ‘Add’ to open the ‘Add Engine’ form. Give this engine the label ‘Red’ and fill in the form with the values you noted down in Step 2. Select ‘Save’ to finish connecting Red to Zwerm.
Before you move on, there are two values you need to note down. For both engines, in the list click on the eye-icon then view their details. In the popup window, find the ‘Engine ID’ shown at the top and write down its value.
Now it’s time to see your bots in action! In the left navigation, click on ‘Open in app’ to open the bot in the Zwerm app. Login (if necessary) and select ‘Testing’ in the navigation. If everything is set up correctly so far, you will immediately see Blue’s introduction message: “Hello. This is blue speaking. I talk about everything that’s blue.”
Go ahead and have a talk with blue. Try asking it the following:
- What are your favourite things?
- Tell me something about what you like.
- What do you like?
At the moment, Blue is the only bot you can talk to. Move onto step four to change this.
Step 4: How to change between your bots
Zwerm makes it super easy to add more complex functionality to your DialogFlow agent. The next step is to hand over from ‘Blue’ to ‘Red’ when the user requests it.
To do this, open the demo-blue agent in DialogFlow again, and select ‘Intents’ in the sidebar. as you can see, you already have an intent set up for ‘Talk to Red’. Select it in the list to edit the intent and scroll all the way down to ‘Responses’ section at the bottom. You will now add an additional response to this intent, to instruct Zwerm to hand the user conversation over to ‘Red’.
Click ‘Add Responses’ and select ‘Custom payload’. Copy the following JSON into the editor field and make sure to replace TEAM-NAME with the name of your team and RED-ENGINE-ID with the value you wrote down in Step 3. Now select ‘Save’ at the top right of the page until your agent is rebuilt. You will get a notification about this.
"query": "get started"
So, what happens here is that ‘Blue’ now returns to the zwerm.handover event as part of its responses for this intent, which causes the conversation route to update and the new event to be sent to the engine.
Long story short, the user is now talking to Red, and Red has received the zwerm.welcome event which will make Red welcome the user.
Try it out! Send Blue bot one of these messages:
- Talk to Red
- I’m bored
- Go away!
Now that you’re having a conversation with Red, how about switching back to Blue? It’s a very similar process. Open the ‘Red’ bot in AWS. Select the ‘TalkToBlue’ intent in the left column. Scroll down to responses and click ‘Add Message’. Change the type to ‘Custom Markup’ and copy and paste the following code into the editor field. Don’t forget to replace TEAM-NAME with the name with the name of your team and BLUE-ENGINE-ID with the value from previous steps.
Now scroll further down and click ‘Save Intent’, then click ‘Build’ in the top right corner and confirm in the pop-up. This will take a few seconds, but once done click the blue ‘Publish’ button next to it, choose the ‘demo’ alias and click ‘Publish’ again.
(Note: it might take a while until you receive the updated version of the Lex bot. It’s best to use an anonymous user in Zwerm’s testing tool.)
Step 5: Go for it!
That’s it! You’re good to go. Switch between your bots as you please. You can now see firsthand the benefits of having two bots, so why don’t you try it with your customers?