How to Integrate a Dialogflow Chatbot With Angular JS
In this article, see how to integrate a Dialogflow chatbot with Angular JS.
Join the DZone community and get the full member experience.Join For Free
There are numerous posts about developing a chatbot using Dialogflow. But creating a chatbot isn’t enough. Connecting Dialogflow to the web interface is even more interesting and challenging. With Angular being a popular and emerging platform, here is our guide to integrating Dialogflow chatbot with Angular JS.
In our quest to simplify chatbot integration with different platforms, we have previously written guides to integrating chatbots with websites and apps.
To get started, you would need a Dialogflow chatbot or working knowledge of Dialogflow and Angular JS. To integrate the chatbots with Angular, you will need a Kommunicate account. All the aforementioned tools have free to try out.
If you don’t have Kommunicate a/c, signup here for free – we will need this in further steps.
Steps to Integrate Dialogflow Chatbot With Angular JS
I am going to explain how I connected Dialogflow and Angular with the help of Kommunicate.
Note: To keep it very simple and straight this tutorial explains with really basic and plain code development. Also to mention this project can be found on GitHub. To get an in-detail tutorial on how to integrate the bot into a website you can check here.
Step 1: Create Your Dialogflow Chatbot
To get started, you can easily create a chatbot in Dialogflow or edit one of their provided sample chatbot templates. To go further, you can create your own Intents & Entities.
Step 2: Integrate Dialogflow Chatbot With Kommunicate
Now, navigate to your Dialogflow console and download the service account key file. Here are the steps to locate the file:
- Open Dialogflow agent settings (gear icon on the left panel)
- Click on the google cloud link which is mentioned in the google project bar
- In the Google, cloud page navigate to Credentials section by clicking on API’s & services
- Under the “Credentials section” find the service account and click on edit for Dialogflow integrations
- In the bottom of the screen click on ADD key button and create key option, JSON key will be downloaded
To integrate Dialogflow CX into Kommunicate follow the same instructions to download the JSON key and mention the Agent Id in the kommunicate dashboard
To get the Agent Id: Go to Dialogflow CX console >> Select the Project >> In the Agent you have created ‘Copy the agent name to the clipboard will be in the format mentioned below, where the Agent Id is
Setup your bot’s name and profile picture and choose whether to allow the bot to human handoff for your newly created bot. Click Finish bot integration setup and voila, your bot is now integrated.
You can check/edit your integrated bot using the below path:
Dashboard →Bot Integration → Manage Bots: You can check all your integrated bots here.
Dashboard → Bot Integration. Once finished, your Dialogflow section will have a green icon with the number of bots are you have successfully integrated.
Step3: Install the Angular CLI globally.
To install the CLI using npm, open a terminal/command prompt, and enter the following command:
Now, create a new workspace and initial app project. Run the CLI command ng new and provide the name my-app, as shown here:
The initial app project contains a simple Welcome app, which is ready to run. Angular includes a server so that you can easily build and serve your app locally.
Now, navigate to the workspace folder (my-app).
Launch the server by using the CLI command ng serve, with the –open option.
Step 4: Installing Chatbot in the Angular Component
Install chatbot on the angular component. The CLI will create the first Angular component. It is the root component and is named app-root.
Run any code editor and open workspace folder (my-app).
Note: Components are the fundamental building blocks of Angular applications. They display data on the screen, listen for user input, and take action based on that input.
The ng serve command launches the server, watches your files, and rebuilds the app as you make changes to those files.
The –open (or just -o) option automatically opens your browser to http://localhost:4200/.
If you run the browser, you should see a chat widget screen pop up and that means your chatbot is ready. This is how you integrate Dialogflow chatbot with Angular using Kommunicate in few simple steps.
Published at DZone with permission of Devashish Mamgain. See the original article here.
Opinions expressed by DZone contributors are their own.