Skip to main content

Facebook Bots with Dialogflow

Alexander Hauenstein 3 min read
Facebook Bots with Dialogflow

At the last meeting of the innovation:now meetup series, innFactory co-founder Anton Spoeck presented the Facebook bot innMensa. For those who weren’t at the meetup, here’s a small summary: https://innfactory.de/news/meetup-zum-thema-machine-learning-sprachtechnologien/

The task of this chatbot is quite simple yet delivers relevant knowledge for every student. The bot is integrated into Facebook Messenger and provides information on request about what is being served in the canteen at Rosenheim University of Applied Sciences. Using this use case, the following will show how a chatbot can be created with Dialogflow. Dialogflow is a subsidiary of Alphabet (Google) and offers tools to analyze and utilize language.

Let’s start with the user input, which contains the user’s intent. Understanding this intent is essential to formulate an appropriate response. Dialogflow offers so-called “Intents” for this purpose.!

An intent consists of, among other things, example sentences and words that serve Dialogflow to determine the user’s intent. The more example sentences you provide, the greater the probability that Dialogflow can correctly assign a user’s input.

The figure shows four examples used to recognize the intent of a user who wants to know what is being served on a specific day.

Marked are words that imply a specific time. This brings us to the next component of an intent: the parameters.

Intents may need parameters for a correct response. In our case, the date is a relevant parameter to be able to determine for which day a user wants to know the menu. This parameter is mandatory in our example, which can be set in Dialogflow using the “Required” checkbox.

In case the intent but no date is recognized, Dialogflow offers the possibility to ask the user follow-up questions. In the second figure marked as “Prompts.”

Every word that stands for a date is marked with the system entity “@sys.date”. Dialogflow then takes over the correct translation into the corresponding date. Additionally, entities can also be created manually.

At this point, a brief interim status:

So far, the bot recognizes when asked about the menu and assigns a date to this request.

But how does the bot find out what is being served on that date?

At this point, Dialogflow needs some assistance through additional functionality. This can be incorporated with manageable effort, as Dialogflow can transmit requests to a webhook and receive its responses.

For the innMensa bot, an AWS Lambda function is used. It receives the name of the intent as well as the corresponding date in an HTTP request. Within the Lambda function, a request is then made to the OpenMensa API using the date, which can look like this:

The request returns all dishes in JSON format. The figure shows a partial excerpt of the response to the request.

After processing the response, Dialogflow receives it via HTTP response and can then forward it to the user.

Finally, it only remains to clarify how communication between Facebook and Dialogflow works. Dialogflow offers simple integration options and detailed instructions for some services, including Facebook Messenger. More information: https://dialogflow.com/docs/integrations/facebook

In conclusion, here’s the complete process summarized in a graphic:

Written by Alexander Hauenstein Software Developer

Software Developer bei innFactory mit Leidenschaft für skalierbare Softwarelösungen.