Comments (2)
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.
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)
- Your test middleware_post has a bug in it
- Temporary Error
- referral event handler is not working HOT 3
- Trying to get setGetStartedButton working HOT 2
- Undefined Error on like
- Updating Persistent Menu for Platform 1.4 HOT 4
- npm package on package.json HOT 2
- Cannot read property 'forEach' of undefined HOT 2
- Support for messages with (image) attachments
- Greeting Text
- Bot throwing undefined 'forEach' on functions without parsed.entry[0].messaging[0] HOT 1
- getProfile() return undefined HOT 1
- An in-range update of request is breaking the build 🚨 HOT 4
- The package in NPM is not updated HOT 2
- Version 10 of node.js has been released HOT 1
- Getting Cannot read property 'forEach' of undefined HOT 1
- Facebook Graph API 2.6v will be deprecated. HOT 4
- More examples for bots HOT 1
- Insufficient permission to access user profile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from messenger-bot.