Comments (10)
Hi,
Sorry for the late reply on this issue.
The client refers to the bot that is receiving the messages from the user.
Although there is no specific handler created for the messages as there is for validation, it can easily be created manually as per the example below. I am doing some work on it now to add Typescript support and will add an inbuilt message handling option as well.
routes.js
...
const router = require('express').Router();
const facebook = require('fb-messenger-bot-api').ValidateWebhook;
const postBackController = require('./postbackController');
router.get('/api/webhook', facebook.validate);
router.post('/api/webhook', postBackController);
postbackController.js
const client = new facebook.Client(process.env.PAGE_ACCESS_TOKEN);
const postBackController = function postBackController (req, res) {
let event = req.body.object.entry[0].messaging[0];
let senderId = event.sender.id;
let userMessage = event.message.text;
client.sentTextMessage(senderId, `You said: '${userMessage}'`);
}
This would be the barebones example of echoing user message. I will add class to handle extraction of this nicely this week or next latest ;)
from fb-messenger-bot-api.
Hey @teomaragakis ,
As mentioned, I have updated the code to TS, has taken a while longer than wanted due to life but it is cleaner, more feature rich and more generic at same time.
from fb-messenger-bot-api.
Took far longer than expected due to lack of time but I am releasing today the postback extraction and parsing logic in a shape & form. Open to suggestions for new features !
from fb-messenger-bot-api.
@weekian Okay so I think figured it out:
Listening for messengers requires a post request endpoint, and from what I see there is no route that receives post requests. So the answer is no, There's no handler for receiving messages. I'll try to write something and post it in a gist.
from fb-messenger-bot-api.
@crisboarna, I'd suggest adding this to the current version before upgrading to TS, but that's just me. Thanks for the great job, I'm learning a lot from your code.
from fb-messenger-bot-api.
@teomaragakis, the code already exists and am using it in another repo, just need to port it over, adding it before TS would result in having to do two refactors instead of one.
Glad to hear it's educational ^^, hopefully on how to write code and not on how to not write it :P
from fb-messenger-bot-api.
hopefully on how to write code and not on how to not write it :P
@crisboarna well I don't have enough experience with node to judge yet.
Just kidding, your code is fine. :) Definitely learning some good JS OOP practices from it.
from fb-messenger-bot-api.
@crisboarna, looks great but my TS game is weak so I'll just take your word for it :)
Can't wait to see the postback functionality!
from fb-messenger-bot-api.
Did you forget to push? :)
from fb-messenger-bot-api.
It has been pushed, just a little later than I was hoping for (27 Sept), but it got there :)
from fb-messenger-bot-api.
Related Issues (18)
- Update for the latest API HOT 2
- support for tag message
- OAuthException on quickreply HOT 1
- Great library - Can we add a method or configuration based auto validation of webhook messages HOT 6
- `proxyData` parameter is not optional in`Client` constructor HOT 2
- Template (and builder) classes are not exported HOT 2
- The automated release is failing 🚨
- The automated release is failing 🚨
- BUG: Recipient is required HOT 5
- BUG: the message parser doesnt seem reflect the underlying data. HOT 6
- Attachments can be mized array of normal and fallback one HOT 2
- Don't return 'Promise<{}> | undefined' from the api calls HOT 3
- The IGenericTemplateElement interface default_action missing a required "type" attribute HOT 1
- Support for get_started button
- Don't reject bad requests HOT 1
- validateMessageIntegrity method doesn't use the payload body HOT 2
- API mismatch for Persistent Menu 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 fb-messenger-bot-api.