-->

How does Facebook Messenger connect with Wit.ai Bo

2020-05-21 06:07发布

问题:

In Facebook's documentation they refer to wit.ai Bot Engine, but I can't find anywhere online where its explained how to connect the Story that you build in Wit with your Facebook Messenger App?

回答1:

Wit.ai needs an input - user input. Sentence, phrase, word - to give you back the analysed results.

So first when you say "your Facebook Messenger app" - you need to make sure you are handling the messenger part by itself: have a code in your language of preference running on the server\your laptop which can receive the text which is sent to the messenger account on Facebook.

When you get that working, you will have to use one of Wit.ai libraries for the code language you are using to pass that phrase you receive from the user chatting through the messenger to Wit.ai "library" which will communicate it "to the wit.ai stories" you have and get the result from them.

For example for Python:

  • Library to handle FB Messenger chatting
  • Wit.ai library to pass the user input "to stories and get result"


回答2:

You can integrate Wit to any messaging API. Using the Messenger Send/Receive API for example, you will be able to get and receive messages from/to Messenger users. Wit.ai can then parse the messages and predict the next response.

Here is an example in Node js: https://github.com/wit-ai/node-wit/blob/master/examples/messenger.js



回答3:

I reviewed the latest updates on wit.ai. It seems that Wit.ai does not have an in-built integration with Facebook Messenger. That is, you can't plug it into Facebook Messenger directly by using the page access tokens etc.

What you'll need to do instead is set up a webhook where Messenger will send callbacks with the details of the user's message. If you want you can enable Facebook's in-built NLP too.

Then inside your webhook, send a call to Wit.ai, and get its output in JSON. Then you must process the JSON and send a reply back to the customer using a Sendmessage API call.

It's a bit long-winded, but if you have this setup, you can potentially use any AI engine in the backend. Including wit.ai or dialogflow.