Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Send middleware - who is the bot talking to? #551

Closed
arnthorsnaer opened this issue Dec 13, 2016 · 4 comments
Closed

Send middleware - who is the bot talking to? #551

arnthorsnaer opened this issue Dec 13, 2016 · 4 comments

Comments

@arnthorsnaer
Copy link

I'm adding a custom middleware to send (controller.middleware.send.use) which is working as far as getting information on what text is being send and what the channel is but I am unable to figure out the user being communicated with.

Can I figure this out using the channel in the message?

@benbrown
Copy link
Contributor

@arnthorsnaer you can look at the message.user field. Is that not working?

@arnthorsnaer
Copy link
Author

arnthorsnaer commented Dec 16, 2016

Thanks for the answer @benbrown

But, it does not work for me.
Given this middleware function

controller.middleware.send.use(function(bot, message, next) {
    console.info(message)
    next();
  });

When I use "bot.startPrivateConversation" to send a message to the user the message object contains {text: "relevant text", channel: "D13E96..."}

Additionally when I use "bot.api.chat.postMessage" then the middleware function does not execute.

@arnthorsnaer
Copy link
Author

arnthorsnaer commented Dec 19, 2016

Another strange thing I noticed - when using the bot.api.chat.postMessage the controller.middleware.receive.use middleware executes (strange since I thought it only executed when the bot receives a message.

Is it possible that the middleware functions only work with RTM? And that in case of postMessage the middleware function is triggering because from it's perspective it is receiving the message?

@benbrown
Copy link
Contributor

Hey @arnthorsnaer sorry I misread your original question. There is not currently a way to reliably know who the message is addressed to, because for slack, the only required field is the channel.

This is an interesting point, and it may be that we should ensure that a user field is present there since Botkit is always talking to a specific user, even if in a public channel.

On your second point, I believe you are seeing the receive middleware fire in response to message delivery confirmations and/or echos from the events API.

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

No branches or pull requests

3 participants