New at Slack programming and, admittedly, it's been a while since I've developed much of anything.
I'm looking for direction on how to automatically convert any ticket # posted by anyone in any channel and convert it to a deep link into our ticketing system.
So, perhaps the original message was something like:
"Who is working on Ticket #212373?"
I'd like '#212373' to be automatically be converted to a link into our ticketing system. Bonus points if it will then expand with other details/attributes from the ticket in the target system, such as customer name, issue description, current status, etc.
Can anyone give me some direction, perhaps in showing me which API to target, whether it's possible, recommended approach, etc?
I finally got around to implementing this properly via OAuth, and it's pretty simple given the complexity of what's happening under the hood. To have exactly the behavior you described above, here's what you do:
message.channels
event subscription to your App and set your Request URL.chat:write:user
scope. This is the critical component which allows your App to actually update the user's message.message
events from Slack. In your (and my) situation, you'll want to parse the text
attribute of the event
, which is the message posted by the user.chat.update
back to Slack with the parsed (and linked) text.chat.postEphemeral
when your App parses a message that it cannot update due to lack of permission. You can send the ephemeral message to the user to let him know that he can authorize your app to link things on his behalf.If you want to get message.channels
events from private groups and/or direct messages, you will need to specify the groups:history
and im:history
, respectively.
Take note that you will need to additionally handle message_changed
events if you want to maintain links in the edited message, because Slack strips the link tags when the user edits their message directly. message_changed
events are structured a bit differently with the the original message contained in a new message
parameter and the previous message in a new previous_message
parameter but can otherwise be parsed and updated the same as simple messages.
Furthermore, you can supply a properly formatted attachments
parameter to your chat.update
method to add the additional details you mentioned in your question such as customer name and ticket info.
This is possible, but not encouraged by the Slack Team. The method is deprecated and may be removed in the future.
chat.update
endpoint authenticating as
the token generated above.I have implemented the exact behavior that you requested and it has worked flawlessly for several years. However, be aware of the following downsides:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With