Get message event_id from reaction_added in slack api - slack

Using the slack_sdk in python, I am attempting to store who reacts to a message sent by the bot, and what what specific message they reacted to. The payload I get from a reaction_added lets me know who sent the message someone reacted to, but not the specific message event_id. Is there some way where I can tell what message someone reacted to?
the Payload received does not seem to carry the data I need. I checked the api docs, but couldn't find how to get more information on the event_id of a message someone reacted to.

The Event IDs for each event are only so useful for correlating activities between events. You won't really find a way to link the actual event describing "what happened" with another event.
However, you can correlate what the events reference together. In reaction_added you receive a bundle of data in item describing what the item_user reacted to. When it's a message, type will be set to message, channel will indicate the ID of the channel where the message belongs and the ts value will point to a specific message ID in that channel.
If you previously received (& persisted) the message that has been reacted to, you'll need to correlate that with the ts and channel values you'll also find in each message.
If you don't have that message and need more data about it and have the appropriate permission scopes, you can use the Web API method conversations.history to fetch a single message as documented here.

Related

Slack `member_joined_channel` - how to check if my bot was invited?

I want to send a message to any public channel that my bot gets added to. I notice there's the member_joined_channel event as documentated here, however I'm not sure how to figure out when to determine if my bot was the invited member. I know there's the user property, but I don't want to hardcode my bot's user ID.
I'm not familiar with the slack API, but i found this endpoint :
https://api.slack.com/types/conversation
In the response, you have a flag is_member which contains what you need I think :
is_member indicates whether the user, bot user or Slack app associated
with the token making the API call is itself a member of the
conversation.
EDIT:
then, you can retreive the list of public channel and have this flag on every channel accessible :
https://api.slack.com/methods/conversations.list
If you are writing a WebSocket-based "RTM" bot, you can listen for the channel_joined event, which is sent only for your own user/bot.
For the more typical Webhook-based bot, the best choice is to listen for the member_joined_channel event and compare the user field if you want an event-based implementation. Hardcoding or otherwise storing your bot's user id is a necessity.
Otherwise, as suggested in the previous answer, you can periodically query all conversations with the conversations.list method and check if you have become a member using the is_member field.
In case one of these methods does not provide the is_private field that you need to determine whether a channel is public, you can use the conversations.info method, which returns a channel object with the is_private field.
Coversation info is your friend https://api.slack.com/methods/conversations.info

Is conversation Id in slack immutable?

I need to send messages to channels. Documentation give advice to receive all channels, pick you channel by name and after all send message by conversationId.
I want to cache the value of conversation id. But I want to be sure it won't be changed.
Documentation says
Recently we began preserving the channel ID of channels converted from
public to private.
So we can conclude, that it is immutable now
https://api.slack.com/changelog/2018-09-more-reasons-to-be-a-conversations-api-convert

SQS distinguish between duplicate and failed/retry messages?

I am writing an application in Lambda that is invoked by SQS messages.
I would like to be able to tell the difference between an invocation resulting from a "duplicate" message vs one resulting from a previous failure/retry (both SQS and Lambda will retry in case of failure).
Is the messageId the same for duplicate messages, or just the body? If they are different I might be able to track a messageId against a key from the body to identity duplicates.
TIA.
Ideally, you would want to store the message id some kind of database once you successfully process the message. And the next time around if you get a message with a message id already present in your store, you will know that this has been successfully processed.

How to get message_id of emails sent using transmission?

We're moving from Mandrill to SparkPost. We figured that SparkPost's transmission is the closest thing to Mandrill's send-template message call.
Mandrill responded to those calls with a list of ids and statuses for each email. On the other hand SparkPost returns a single id and summary statistics (number of emails that were sent and number of emails that failed). Is there some way to get those ids and statuses out of the transmission response or at all?
you can get the message IDs for messages sent using the tranmissions API two ways:
Query the message events API, which allows you to filter by recipients, template IDs, campaign IDs, and other values
Use webhooks - messages are sent to your endpoint in batches, and each object in the batch contains the message ID
Which method you choose really depends on your use case. It's essentially poll (message events) vs. push (webhooks). There is no way to get the IDs when you send the transmission because they are sent asynchronously.
Querying message events API, while a viable option, would needlessly complicate our simple solution. On the other hand we very much want to use Webhooks, but not knowing which message they relate to would be troublesome...
The missing link was putting our own id in rcpt_meta. Most of the webhooks we care about do contain rcpt_meta, so we can substitute message_id with that.
I'm stacked too in this problem..
using rcpt_meta solution would be perfect if substitution would work on rcpt_meta but it's not the case.
So, in case of sending a campaign, I cannot specify all recipients inline but have to make a single API call for every message, wich is bad for - say - 10/100k recipients!
But now, all transmission_id are unique for every SINGLE recipient, so I have the missing key and rcpt_meta is not needed anymore.
so the key to be used when receiving a webhook is composed:
transmission_id **AND** rcpt_to

how to debug messages on the queue, who sends them? and what is in the queue?

The Event Queue is a box that get messages and handles them.
Could you please say , where are the messages that PostMessage and SendMessage are stored? and how to tell who send what message?
What variables can be inspected to get the information?
Where are the messages stored?
They are stored in an internal data structure associated with a thread. Note that each thread has zero or one message queues. A message queue is not created automatically for a thread, but created on demand when the thread calls a function that requires a message queue.
Note also that sent messages, those delivered by SendMessage do not appear in the queue. Sent messages are synchronous and so not queued.
How to tell who send what message?
In general that is not possible: Can I determine which process sent my window a message?
What variables can be inspected to get the information?
You cannot. You can use PeekMessage to find out whether or not the queue contains a specific message, or find the first message in a given range. But there is no functionality to dump the entire message queue.

Resources