Monday, January 1, 2024
HomeBig DataThe right way to Construct a Fb Messenger Chatbot Powered by Quick...

The right way to Construct a Fb Messenger Chatbot Powered by Quick SQL on CSV


A chatbot, like every human customer support rep, wants information about what you are promoting and merchandise with the intention to reply to prospects with the proper data. What’s an environment friendly technique to hook up your information to a chat software with out important information engineering? On this weblog, I’ll exhibit how one can construct a Fb Messenger chatbot to assist customers discover trip leases utilizing CSV information on Airbnb leases.

Providers Used

We are going to use the next providers to implement our chatbot:

Loading the Airbnb Knowledge into Rockset

Airbnb information is out there in CSV format for various cities and is split into itemizing, evaluation, and calendar information. From the Rockset console, I uploaded these information for Amsterdam into three totally different collections (airbnb_listings, airbnb_reviews, and airbnb_calendar). You too can add information for different cities into these collections if wanted.


chatbot-create-collection

Alternatively, you might place your information in an Amazon S3 bucket and create a set that repeatedly syncs with the information you add to the bucket.

Writing the Fb Messenger Bot

Utilizing the messenger bot tutorial, I created a Fb web page and webhooks to obtain occasions from the chatbot. You possibly can consult with and familiarize your self with the Node.js venture I created right here.

app.js creates a HTTP server utilizing Specific. The server handles GET requests to confirm webhooks and POST requests to reply to consumer messages.

// Accepts POST requests on the /webhook endpoint
app.submit('/webhook', (req, res) => {
  let physique = req.physique;
  if (physique.object === 'web page') {
    physique.entry.forEach(perform(entry) {
        let occasion = entry.messaging[0];
        if (occasion.message && occasion.message.textual content) {
            // deal with the message
            handleMessage(occasion);
        }
    });
    // Return a '200 OK' response
    res.standing(200).ship('EVENT_RECEIVED');
  } else {
    // Return a '404 Not Discovered'
    res.sendStatus(404);
  }
});

handleMessage.js interacts with Dialogflow and queries Rockset to reply customers’ inquiries.

Utilizing Pure Language Processing with Dialogflow

With the intention to perceive consumer messages and questions, I’ve built-in Dialogflow (apiai) in my venture. Dialogflow means that you can create intents and extract meanings out of phrases utilizing machine studying. To hook up with Dialogflow out of your software you have to use Shopper entry token to create the consumer object.

I created an intent rentalcity and educated it with a couple of phrases to extract the requested metropolis and date for the rental and the variety of individuals within the celebration. Equally, I created a couple of extra intents to reply follow-up requests utilizing contexts. The Dialogflow venture export is included within the recipes github repository.


chatbot-dialogflow

Interacting with the Chatbot

We now have the bot arrange and a mechanism to know customers’ requests. All we want now’s a technique to translate the requests into significant responses. Utilizing Rockset’s Node.js consumer, I’ll question the the collections created in step one.

Let’s begin interacting with the chatbot.


chatbot-interaction-1

The intent to search out listings makes use of the next SQL question:

with listings as (
    choose id, title, value, property_type
    from airbnb_listings
    the place decrease(airbnb_listings.metropolis) like :metropolis 
        and airbnb_listings.accommodates::int >= :quantity
    order by airbnb_listings.number_of_reviews desc
)
choose listings.id, listings.title, listings.property_type, listings.value
from listings, airbnb_calendar
the place airbnb_calendar.date = :date and airbnb_calendar.accessible = :avail
    and airbnb_calendar.listing_id = listings.id
restrict 1

This SQL question makes use of two collections airbnb_listings and airbnb_calendar to extract the rental with the best variety of critiques accessible on the given date.

To get extra data for this itemizing, the consumer can reply with particulars.


chatbot-interaction-2

To reply this we fetch the abstract from the gathering airbnb_listings for the listing_id returned within the earlier question.

choose abstract from airbnb_listings the place id = :listing_id

The consumer also can request the most recent critiques for this itemizing by replying present critiques.


chatbot-interaction-3

The SQL question to get the critiques for this itemizing:

choose feedback, date
from airbnb_reviews
the place listing_id = :listing_id
order by date desc
restrict 3

To take a look at one other itemizing, the consumer sorts in subsequent. This makes use of the offset SQL command to get the following outcome.


chatbot-interaction-4

Abstract

We now have a data-driven chatbot that understands customers’ requests for trip leases and responds utilizing Airbnb itemizing and calendar information! Its skill to offer on the spot replies leveraging quick SQL queries on the Airbnb CSV information additional enriches the client expertise. Plus it was comparatively simple to attach the chatbot to the underlying Airbnb information set. The complete technique of constructing the chatbot took me lower than a day, from loading the dataset into Rockset and writing the chatbot to establishing interactions to reply with the related data.





Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments