Slack – Can Slack convert/substitute strings into another output

slack

I feel like I've researched this to death, but I'm sure it must be possible (certainly considering the scope of Slack's customisation).

The general concept would be to allow a user to type in a string of a predetermined pattern, then that could be converted.

An example would be like the Giphy plugin, which takes /giphy {$string}.gif and dynamically alters the output by posting an image.

The intended output would be so you could type in something along the lines of #12345 (or even /foo 12345) and this could produce a fully formatted string.

For example:
/foo 12345

is changed to output http://foo.bar/p=12345

I'm simultaneously skeptical that it can't be done, and that it can be done!

I'm hoping that someone has managed a solution that wouldn't pointlessly use hooks or bots (as generating a new message wouldn't really be very slick at all).

Best Answer

You will need a Slack app or at least an internal integration.

Then just create a slash command, e.g. /foo, which will call your Slack app. Then in your Slack app you can just respond with a new message which will automatically overwrite the previous one (containing the /foo xyz) with whatever content you like. Or you can use additional API methods like chat.update to do the same.

Please also consider using Stack Overflow for further questions about programming with the Slack API.