/chatbot-with-algolia-answers

Chatbot with Algolia Answers and Dialogflow

Primary LanguagePythonMIT LicenseMIT

Chatbot with Algolia Answers and Google Dialogflow Messenger

This sample app implements a chatbot that answers your questions about Covid-19 vaccines. With chatbots, you can ask questions using your natural language instead of using artificial search queries. Algolia Answers extracts the users' intent from their questions (semantic understanding) and offers best-matching answers without the need for extra training of the model.

A flowchart of the chatbot with Algolia Answers sample application

Features

The sample app uses the following features:

  • 🤖 Chatbot building made easy with Google Cloud Dialogflow

    The sample app uses Dialogflow Messenger, a visual chatbot interface (1). A webhook service sends the question to Algolia Answers, which handles all user intents (questions).

  • 🧠 Semantic understanding using Algolia Answers

    The heavy lifting is performed by Algolia Answers (3), Algolia's semantic search API. Answers combines information from the search index, such as relevance, synonyms, or rules, and applies semantic understanding of small snippets to rank which snippet best answers the question (4). You don't have to train anything!

    Conventionally, you have to train Dialogflow by providing training phrases and their variations together with matching responses.

    You can also integrate Algolia Answers into existing chatbots by directing only a part of user intents to Algolia Answers while other intents are handled elsewhere. Instead of Dialog Messenger, you can also choose other chatbot interfaces, or implement your own.

  • 📈 Data from the World Health Organization's FAQ on Covid-19 vaccines

Demo (Try it yourself!)

A short movie displaying the Algolia COVID-19 Vaccines chatbot

Access the demo

How to run the sample app locally

The sample app implements two servers in these programming languages:

The client is a single HTML page with the Dialogflow Messenger.

1. Clone this repository

git clone https://github.com/algolia-samples/chatbot-with-algolia-answers

Copy the file .env.example to the directory of the server you want to use and rename it to .env. For example, to use the Python implementation:

cp .env.example server/python/.env

2. Set up Algolia

To use this sample app, you need an Algolia account. If you don't have one already, create an account for free. Note your Application ID.

In the .env file, set the environment variables ALGOLIA_APP_ID:

ALGOLIA_APP_ID=<replace-with-your-algolia-app-id>

3. Create your Algolia index and upload data

After you set up your Algolia account and Algolia application, create and populate an index. Or, you can use the same data as the demo, The World Health Organization COVID-19 FAQs.

To upload your data, you can use the Algolia dashboard or use on of Algolia's API clients.

After creating the index and uploading the data, set the environment variable ALGOLIA_INDEX_NAME in the .env file:

ALGOLIA_INDEX_NAME=<replace-with-your-algolia-index-name>

4. Set up Algolia Answers

Follow the instructions in Algolia's documentation to set up Algolia Answers for your index. After you added Algolia Answers to your account, set the environment variable ALGOLIA_API_KEY in the file .env.

ALGOLIA_API_KEY=<replace-with-your-algolia-api-key-with-algolia-answers-acl>

5. Create and configure a Dialogflow agent

This sample app uses Google Cloud's Dialogflow to bootstrap the chatbot and the fulfillment webhook feature to connect it to Algolia Answers.

  1. Follow the Dialogflow guide to create an empty agent.
  2. Replace the default fallback intent with the file from the sample. The default fallback intent is the answer shown, when the agent couldn't find a matching response.
  3. Populate the agent-id variable in the index file

6. Follow the instructions in the server directory

Each server directory has a file with instructions:

For example, to run the Python implementation of the server, follow these steps:

cd server/python # there's a README in this folder with instructions
python3 venv env
source env/bin/activate
pip3 install -r requirements.txt
export FLASK_APP=server.py
python3 -m flask run --port=4242
  1. Expose your development server to the internet. For example, you can use ngrok.
  2. Add the public URL of the development server to the Dialogflow webhook so it can use it to answer the queries.
  3. Enter questions in the chatbot!

Authors