crisboarna / fb-messenger-bot-api

NodeJS Facebook Messenger API for bots to send messages and setup events to Facebook.
https://www.npmjs.com/package/fb-messenger-bot-api
MIT License
34 stars 17 forks source link

BUG: the message parser doesnt seem reflect the underlying data. #62

Closed MartinSahlen closed 5 years ago

MartinSahlen commented 5 years ago

The parser works great - but it seems to add an extra layer of wrapping around a message - you can clearly see this if you just do a console.log of the parsed message and compare with the class and fields that should be returned.

Currently i need to cast the messages that come out, I will give an example shortly.

MartinSahlen commented 5 years ago

This is what I had to do:

import {
  FacebookMessageParser as messageParser,
  FacebookMessagePayloadMessagingEntry,
} from 'fb-messenger-bot-api';
import { Request } from 'express';

export const parseMessagePayload = (req: Request) => {
  const messages = messageParser.parsePayload(req.body);
  // tslint:disable-next-line:no-any
  return (messages as any) as FacebookMessagePayloadMessagingEntry[];
};
MartinSahlen commented 5 years ago

@crisboarna Did you see this?

crisboarna commented 5 years ago

Hi @MartinSahlen , I am looking at it now.

mohyt commented 5 years ago

@crisboarna : IMO, the messages received from facebook messenger and they need to casted in proper types. If you look in to https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messages and https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-deliveries

I think as part of parse payload the parsed payload type should be decided.

crisboarna commented 5 years ago

:tada: This issue has been resolved in version 4.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

crisboarna commented 5 years ago

Hi, I had a look over it and the issue was that the return type of FacebookMessageParser.parsePayload() is FacebookMessagePayloadEntry whereas the correct type should be FacebookMessagePayloadMessagingEntry indeed. Pushed changes and 4.2.0 should have this fixed and not require anymore casting. Thanks for the heads up :)