forward a message with slack API getting invalid_blocks error - slack

I'm trying to simply get a message from one channel and forward it to another.
all I do is listen to messages on the channel, get the blocks, i.e.:
[{"type":"rich_text","block_id":"AHdW3","elements":[{"type":"rich_text_section","elements":[{"type":"text","text":"z"}]}]}]
and send them to another channel
client.chat.postMessage({
blocks: blocks,
channel: context.targetChannel,
});
I'm getting an invalid_blocks error, even tho this must be valid blocks since they are generated by slack themselves.
any ideas here?
I also tried to remove the block_id but got the same result.
I'm using bolt framework btw, but that shouldn't matter.

Turns out the blocks from 1st client slack apps are rich_text, which isn't supported in the api.
so the way to go is grab the text from the message and post that as is.
See here for context
https://github.com/slackapi/bolt-js/issues/1324

Related

Need messages in single line from Slack Bot Webhook app

I'm using slackBot webhook curls to send messages to slack, but i see the message being spilled over to multiple lines.
Is there any way i can make them appear in single line.
Below one is the message coming from webhook but i am wishing to have it like the way its depicted in top message of the image.
I've already tired to use coded blocks as well but even that didnt help me much.

Cannot delete message in IM channel as Slack bot

I'm trying to use chat.delete on a "user" channel, the same as you do with chat.postMessage, however I keep getting a channel_not_found error.
slack.api_call(
"chat.delete",
channel=userID, # Exact same value as used with chat.postMessage
ts=ts
)
Is this a limitation in their API? Is there a way to achieve this?
Turns out chat.postMessage will use the SlackBot channel when addressing a single user. The proper way of communicating via IM with a user is to use conversations.open. When I used that everything works as expected.

Unable to get timestamp of the message posted by Slack App

Whenever my app posts ephemeral message to Slack channel (in response to a query by a user), I am unable to get the timestamp of my Slack app response. As I want to delete it once the user has made a selection using one of the buttons. Although I have subscribed to 'message.channels' event, I don't get a notification to my app whenever my app posts in the channel (in response to the user input), therefore, I am unable to get the timestamp of the message which I'll use to delete it. All I want is the timestamp of the message posted by my app so that I can delete it but I am unable to receive the timestamp. Please help!
For e.g. in Giphy app for Slack. Let's say the user invokes the app by calling '/giphy [dog]' where 'dog' is just an example of a search term. The app responds by sending a gif and user can either send it, shuffle to the next one or cancel it. I want a similar capability of cancelling the app response but I need the timestamp of the message in order to do so therefore I am asking for help.
Thanks.
Your approach can not work, because Slack is handling ephemeral messages differently from "normal" messages. They are only visible by one user and can not be modified by API methods (e.g. deletion).
But of course its possible to replace ephemeral messages. Here is how:
Your app can just reply to the interactive message request from Slack with a new message. That new message will by default override the original message including ephemeral messages.
You can reply in two ways:
Directly reply to the request from Slack with a message within 3 seconds
Send a message to the response_url from the Slack request within 30 minutes.
See here for the official documentation on how to respond to interactive messages.
This approach works both with interactive messages and slash commands.
See also this answer for a similar situation.

Slack POST multiple messages to a channel at once

I need to post multiple bot replies (responses determined dynamically) to the same channel.
The obvious way seems to be to do an HTTP POST for each message in succession using this API method: https://api.slack.com/methods/chat.postMessage
Is there a way to send messages to Slack in bulk to post to the same channel? The order in which the messages get rendered need not be important for me.
No, there is no bulk variant. So you basically need to build your own bulk message sender.
Keep in mind that there is a request limit of 1 message per second or your API requests will fail.
There also is a 3 seconds request time-out for many requests between Slack and your app. (e.g. for direct response to slash commands). So if your bot needs to send many messages you want to use an approach that allows you to send them asynchronously.
One solution to this problem that works very well for me is to use a messaging queue for all Slack messages sent from my bots.
You can try multiple messages as attachements -> https://api.slack.com/reference/messaging/attachments

Getting message info from Messages.app with AppleScript

I’m looking to get information about individual messages in chat threads in Messages.app.
I can get individual chat threads:
set firstChat to first chat
I can get everything I ever wanted to know about file transfers (media sent/received via iMessage):
get properties of the last file transfer whose direction is incoming
I can handle messages as they arrive (which is pretty magical):
on message received msg from bud
processIncomingMessage(msg, bud)
end message received
I just can’t figure out how to get information about individual messages. I’ve pored over the dictionary for Messages.app. It’s been super helpful up until I reach chat, then it seems I can’t get more specific than a chat thread.
The incoming message handler is great, but it doesn’t give me anything interesting in the message parameter. I can’t even get an index of the message.
Have I missed something, or is it not possible to get information about individual messages?
I have officially declared “f**k it” and given up on finding an AppleScript-y way of getting messages. Everything I need is encased in glorious SQLite (~/Library/Messages/chat.db). Thank you all for your help, I couldn’t have done it without you, keep up the good work, etc. etc.
tell application "Messages" to set lastmessage to subject of first text chat

Resources