Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send middleware after ask() or addmessage() does not append recipient to message (Facebook) #1921

Closed
HamzehEila opened this issue Mar 4, 2020 · 5 comments

Comments

@HamzehEila
Copy link

HamzehEila commented Mar 4, 2020

Hey all,

I have this code that asks a question then when the response is received, it goes to another question thread.

`await bot.changeContext(message.reference);
const convo = new BotkitConversation('register', bot.controller);
convo.ask('Please write the POS ID that you would like to register', async (response, mConvo, mBot) => {
convo.addAction('askUsername');
}, 'posId');

convo.addQuestion('What is your username ?', async (response, mConvo, mBot) => {
mConvo.stop();
}, 'username', 'askUsername');

bot.controller.addDialog(convo);
await bot.beginDialog(convo.id);`

This part works fine.
but in the send middleware:
controller.middleware.send.use(async (bot, message, next) => { console.log(message); });

The problem is,
This message does not have the "recipient" field or any field that contains data about the channel, sender or receiver.

When using bot.reply(), the message in send middleware contains the "recipient" field which has that facebook id of the user.

Thanks

  • Botkit version: 4.6.2
  • Messaging Platform: Facebook Messenger
  • Node version: 10.15.1
  • Os: Windows 10
  • Any other relevant information:
@benbrown
Copy link
Contributor

benbrown commented Mar 4, 2020

There are a lot of issues with the sample code you posted.

  • You should define the structure of your dialog ONCE and add it to the bot when it first boots up.
  • You cannot make changes to the structure of the conversation when it is active -- calling convo.addAction inside the ask callback will cause issues

The send middleware will be seeing the message in its "botkit" form before it is translated into a Facebook API call where the recipient value is mixed in.

@HamzehEila
Copy link
Author

Thanks Ben, I'm new to Version 4, so I appreciate your feedback.

I use the send middleware to save the messages that are sent to the users from the bot, and i include the text of the message + the recipient id for logging and debugging purposes, so it's crucial for me to have the recipient id there.

I hope this makes the problem clearer, I haven't been able to solve this yet.

Thanks.

@benbrown
Copy link
Contributor

The value should be present somewhere in the message you get in the middleware - I believe it will be in message.conversation.id

@stale
Copy link

stale bot commented May 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 13, 2020
@stale stale bot closed this as completed May 20, 2020
@pgoldweic
Copy link

I think that this issue is likely the same as #2030 and also my latest #2062, as it concerns botkit middleware and not Facebook in particular. In summary: no information about the recipient is available within the send middleware as part of the message, if the message is part of an ongoing convo. Unfortunately, this is really crucial information for a bot application :-( (e.g. it's impossible to log properly without the recipient/user id).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@pgoldweic @benbrown @HamzehEila and others