Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

controller.api.nlp.enable() causes error message #1086

Closed
rogerweb opened this issue Oct 12, 2017 · 5 comments
Closed

controller.api.nlp.enable() causes error message #1086

rogerweb opened this issue Oct 12, 2017 · 5 comments

Comments

@rogerweb
Copy link

Hi,

Using controller.api.nlp.enable() is causing the following "info"/ERROR message to be printed:

info: ERROR in build-in API call:  Invalid parameter

Versions and OS:

  • botkit-starter-facebook 0.0.2
  • botkit 0.6.4
  • Ubuntu 17.04

I found this controller.api.nlp.enable() in the "Botkit and Facebook" documentation: https://github.com/howdyai/botkit/blob/master/docs/readme-facebook.md

I'm trying to figure out how to "hear" Wit.ai "intents" that my bot is already receiving directly from the messages from Facebook Messenger Built-in NLP that I've enabled using FB dev pages.

What exactly this phrase means?

Facebook's NLP option can be enabled by calling controller.api.nlp.enable() in your Botkit app.

Do I need to write a middleware to make bot kit to "hear" Wit.ai entities?

Thanks for any support.

@rogerweb
Copy link
Author

It might be related to #943

@ouadie-lahdioui
Copy link
Collaborator

ouadie-lahdioui commented Oct 14, 2017

Yo,

To enable/disable FB built-in NLP for your app, you need to toggle the button on/off on your fb messenger settings' page, you can also do the same thing programmatically using the graph API by calling controller.api.nlp.enable|disable().

No, you don't need to create a middleware to make BotKit hearing entities, you juste need to use message.nlp.entities !

To fix your problem, i think that you customized the NLP by specifying a Wit server token in your fb messenger settings' page, if so, you need to call : controller.api.nlp.enable(YOUR_WIT_SERVER_TOKEN), custom token is no more optional in this case.

However, you can reset wit token by clicking reset button in the built-In NLP after choosing the concerned page.

Are you customized NLP via Wit.ai ?

@rogerweb
Copy link
Author

Hi,

Yes, I have customized NLP via Wit.ai and I do have access to the entities via message.nlp.entities because I had manually enabled it via FB messenger settings' page.

Thanks for explaining that the controller.api.nlp.enable|disable() does the same thing programmatically. So I don't actually need this line of code. I tested it anyway passing my Wit.ai server token as you have explained and the error is gone, so please feel free to close this issue.

If you don't mind, I still don't know how to make BotKit to hear my Wit.ai entities/values. For example, I tried the following code:

    controller.hears("greet", "message_received", function(bot, message) {
        bot.reply(message, "Hi, how can I help you?");
    });

where "greet" is one of the possible values of an entity named "intent" that I have configured in Wit.ai:

"nlp": {
    "entities": {
        "intent": [
            {
                "confidence": 1,
                "value": "greet",
                "type": "value"
            }
        ]
    }
}

I also tried with "intent" as the the first parameter to the hears function, with no luck. Should I hear everything and "parse" the message.nlp.entities myself inside the callback?

Thanks again for the support.

@ouadie-lahdioui
Copy link
Collaborator

ouadie-lahdioui commented Oct 16, 2017

Cool 😄

To do that you must change the default string matcher function and create handler functions for your specific intents, Natively Botkit use string matcher based on regular expressions.

In short, you can :

Create an individual handler functions :

controller.hears('greet', "message_received", myCustomHearsHandler, (bot, message) => {
    bot.reply(message, "Hello");
});

myCustomHearsHandler = (test, message) => {
   /* This is not the smarter implementation, but i'm sure that you will code better than */
    let isMatch = false;
    message.nlp.entities.intent.forEeach(function (intent) {
        isMatch = intent.match(test);
    });
    return isMatch;
}

Take a look at the default regex handler for inspiration.

Change the default handler globally :

/* i'm based on the previous myCustomHearsHandler */
controller.changeEars(myCustomHearsHandler)
controller.hears('greet', "message_received", (bot, message) => { ... });
controller.hears('foo', "message_received", (bot, message) => { ... });

in this case you don't need to add you custom handler every time as a parameter to the hears function.

Let me know if it helps !

@rogerweb
Copy link
Author

It does help indeed. Thanks a lot.

Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants