Chatbots can understand and respond to user requests automatically. Chatbot integrations can be useful in a variety of situations, such as customer service, new user registration, e-commerce, and anywhere you want a system to be able to respond to user requests.
With PubNub Functions, you can create a custom chatbot or connect to existing chatbot services, helping you to create real-time interactive conversations for your users. Select from a list of prebuilt Function BLOCKS or build an integration with a service of your choice. Here are a few suggestions:
- IBM Watson Assistant allows you to build a chatbot or virtual agent that can carry out conversations with end users in real time. The block includes a number of cognitive techniques, making your chatbot fully customizable to suit your needs.
- Amazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents without needing any special preprocessing.
- Gupshup is an advanced bot and messaging platform. It enables you to quickly and easily build, test, deploy, and manage chatbots across all messaging channels. The PubNub Gupshup block connects your Gupshup bot to realtime data streams, to trigger actions based on an input.
Getting started with the Gupshup bot API
First, you’ll need to get started with a Gupshup account to take advantage of the Bot API.
Go to the Gupshup signup form and sign up for a free trial using your GitHub or Facebook account.
Follow the wizards to create a new bot integration using the IDE, ensuring that there is an
HttpEndpointHandlerfunction to respond to HTTPS requests from the Function.
Make note of the bot name from the bots section of the dashboard.
Setting up the PubNub Function
To add the PubNub Function, do the following:
Click Try it Now on the Gupshup BLOCK page to import the code directly into a new or existing app as a new Function called
Once you've added the Function to an app, go to your app's Functions list, and click the
botnameconstant with the identifier from the last Gupshup setup step, above, and click the red Save button.
Click Start Module to start the Function, and test it using the Publish button and payload on the left.
For a more detailed overview of writing a function, refer to these instructions on the Functions Overview page.
Connecting your code to a UI
In your HTML file's
<head>section, reference the PubNub scripts:
Define your Angular constructor to initialize a PubNub instance and subscribe to the
YOUR_SUB_KEYwith your app's publish and subscribe keys.
Set up your PubNub
publishfunction to query your Gupshup bot for the time of day:
You'll want to have a button set up in your template to call that function:
PubNubAngularto your main class's
Finally, add a DOM event listener to get your code running: