After reading through the slack API docs, it doesn't appear that incoming webhooks support snippets. The
mode argument doesn't exist for a
message as far as I can tell.
A snippet is a type of
File object in Slack, and you'd need to use the
file.upload endpoint. This question on Stack Overflow says that it's impossible to upload a file via an incoming webhook (though it doesn't have any authoritative source on that). Using that endpoint means you need to use Slack's web API.
From the look of it, using Slack's web API ends up being very similar to using an incoming webhook. They're both REST APIs. The difference is that you need to jump through the additional hoops of authenticating with Slack (and managing the OAuth tokens), manually set the endpoints, and you need to manually specify the channel to post to in your request.
The process of setting up an app through Slack (to get access to the web api) would be off-topic here. Their documentation on this goes over the important details.
I think the only other thing worthy of note is that you'll need to add the base url for the Slack web api (
https://slack.com/api/) to your org's remote sites in Salesforce.
The code that you've copy/pasted from Christophe Coenraets looks like a solid enough base (though it doesn't have anything to gracefully handle errors). Once you're set up, changing the url you send to
QueueableSlackCall() is pretty much all that needs to be done (assuming you're building an appropriate request body).
The request body, being built from a
Map<String, String>, could look something like this
msg.put('token', <OAuth token here>);
msg.put('filename', 'new SF lead for ' + l.leadCompany + ' - ' + l.leadName);
msg.put('title', 'new lead created');
msg.put('content', 'The following lead has been created update:\n' + l.leadName + '\nCompany: *' + l.leadCompany + '*');