Closed MartinSahlen closed 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[];
};
@crisboarna Did you see this?
Hi @MartinSahlen , I am looking at it now.
@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.
:tada: This issue has been resolved in version 4.2.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
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 :)
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.