Giter Club home page Giter Club logo

Comments (10)

crisboarna avatar crisboarna commented on August 27, 2024 1

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.

crisboarna avatar crisboarna commented on August 27, 2024 1

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.

crisboarna avatar crisboarna commented on August 27, 2024 1

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.

teomaragakis avatar teomaragakis commented on August 27, 2024

@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.

teomaragakis avatar teomaragakis commented on August 27, 2024

@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.

crisboarna avatar crisboarna commented on August 27, 2024

@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.

teomaragakis avatar teomaragakis commented on August 27, 2024

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.

teomaragakis avatar teomaragakis commented on August 27, 2024

@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.

teomaragakis avatar teomaragakis commented on August 27, 2024

Did you forget to push? :)

from fb-messenger-bot-api.

crisboarna avatar crisboarna commented on August 27, 2024

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)

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.