Dialogflow-fulfillment-nodejs: Nothing happen when I send custom payload for LINE Messenger

Created on 29 May 2018  路  9Comments  路  Source: dialogflow/dialogflow-fulfillment-nodejs

I'm trying to response message back with custom payload to LINE API (reference for text-message payload: https://developers.line.me/en/docs/messaging-api/reference/#text-message)

const payloadJson = {
          "type": "text",
          "text": "Hello LINE Messenger"
        };
let payload = new Payload(agent.LINE, {});
payload.setPayload(payloadJson);
agent.add(payload);

but when i use agent.add('Hello LINE Messenger'); its work. Is something i'm missing in JSON Payload? Thanks for your help.

bug

Most helpful comment

After working on this issue for entire day, I finally had figured out how to reply custom LINE Messenger message.

Please use the latest code from master branch of dialogflow/dialogflow-fulfillment-nodejs

// NPM installation
npm i dialogflow/dialogflow-fulfillment-nodejs#master

There will be a new option sendAsMessage for Payload constructor, turn it true (default is false).

const lineMessage = { /* LINE message object (e.g. Flex message) */ }
var payload = new Payload('LINE', lineMessage, {
  sendAsMessage: true
});
agent.add(payload);

And then we can send any type of LINE message!

All 9 comments

hello, have the bug been solved? and can you other example for the payload integration on line? Thank you

Still not work here

@clonezer can you paste your fulfillment request here? Your fulfillment request source needs to line up with payload platform otherwise it will just return an empty object. I don't have a request source so had to set my platform to 'PLATFORM_UNSPECIFIED'.

still not working :(

I'm also encountering this when I add an array of RichMessages to my agent for response. I have both Text and Payload types and it seems like Payload objects are not being sent. My platform type on both objects is set to 'PLATFORM_UNSPECIFIED' and I receive all text messages but not payload messages.

After working on this issue for entire day, I finally had figured out how to reply custom LINE Messenger message.

Please use the latest code from master branch of dialogflow/dialogflow-fulfillment-nodejs

// NPM installation
npm i dialogflow/dialogflow-fulfillment-nodejs#master

There will be a new option sendAsMessage for Payload constructor, turn it true (default is false).

const lineMessage = { /* LINE message object (e.g. Flex message) */ }
var payload = new Payload('LINE', lineMessage, {
  sendAsMessage: true
});
agent.add(payload);

And then we can send any type of LINE message!

@ananfang It's work 馃憤

anyone know how to send LINE API flex message or another object from LINE API using fulfillment?,

I did what @ananfang suggest but always send the default response intent

Update:

Found payload is not defined in firebase function logs

I find that based on the source code that there is an undocumented flag you have to set after the agent is created, otherwise, a lot of the stuff is not working right, like agent.conv() return null and custom payload not working etc. here is the rub,
const agent = new WebhookClient({ request, response });
agent.requestSource = agent.ACTIONS_ON_GOOGLE;

if the agent.requestSource is not set, a lot of the routine in the fulfilement doesn't work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SiddAjmera picture SiddAjmera  路  8Comments

gakuba picture gakuba  路  8Comments

sarupbanskota picture sarupbanskota  路  3Comments

kwizfreak picture kwizfreak  路  9Comments

jzxhuang picture jzxhuang  路  6Comments