GithubHelp home page GithubHelp logo

built-in NLP support? about messenger-bot HOT 2 OPEN

remixz avatar remixz commented on May 19, 2024 1
built-in NLP support?

from messenger-bot.

Comments (2)

slidenerd avatar slidenerd commented on May 19, 2024

I double this, I am guessing you will have to modify the handleMessage method to add some callback for handling built in NLP calls

from messenger-bot.

slidenerd avatar slidenerd commented on May 19, 2024

I found how to do that. If you enable built in NLP with the default English language model, the structure of your payload inside bot.on("message") looks as follows

{"sender":{"id":"1264345230309999"},"recipient":{"id":"1796187950609999"},"timestamp":1560751759389,"message":{"mid":"p_lqjiuSBZxsOx13swH47cG5zAB69T8EBhssJlJt9TQ6dHAyn6pQV_ljt-xkjjRJvMZhDV5Y_Trbqlz5ln9999","seq":0,"text":"hey there","nlp":{"entities":{"sentiment":[{"confidence":0.8168874995786,"value":"neutral"}],"greetings":[{"confidence":0.99825531242256,"value":"true"}]},"detected_locales":[{"locale":"en_XX","confidence":0.9997}]}}}

As you can see, you just need to check for the existence of NLP property which contains an ibject of entities

Here is how it works


bot.on('message', (payload, reply, actions) => {
    try {
        console.log(JSON.stringify(payload));
        handleMessage(payload, reply);
    } catch (error) {
        console.log(error);
    }
});

function firstEntity(nlp, name) {
    return nlp && nlp.entities && nlp.entities[name] && nlp.entities[name][0];
}

function handleMessage(payload, reply) {
    // check greeting is here and is confident
    const greeting = firstEntity(payload.message.nlp, 'greetings');

    if (greeting && greeting.confidence > 0.8) {
        reply({ text: `Hi There!` }, (err, info) => { });
    } else {
        // default logic
        reply({ text: `You said ${payload.message.text}` }, (err, info) => { });
    }
}

from messenger-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.