Skip to content

Instantly share code, notes, and snippets.

@seanmarpo
Created July 10, 2018 20:01
Show Gist options
  • Save seanmarpo/723e18a4e2353188ea95f679ae30c3be to your computer and use it in GitHub Desktop.
Save seanmarpo/723e18a4e2353188ea95f679ae30c3be to your computer and use it in GitHub Desktop.
Slack Does Not Respect Parse Value for Incoming Webhooks
// Incoming Webhook Example
// Slack ignores the "parse" value entirely in this case
const { IncomingWebhook } = require('@slack/client');
const url = 'WEBHOOKURL';
const webhook = new IncomingWebhook(url);
var text = '<https://google.com|Click Me Please!> https://google.com'
const message = {
username: 'Test User',
parse: 'full',
text: text,
attachments: [
{
parse: 'full',
title: 'New Feedback:',
text: text,
image_url: 'https://test.image',
}
]
};
webhook.send(message, function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Message sent: ', res);
}
});
// WebClient Example (Send message as a Bot User)
// Slack respects the "parse" value in this case
const { WebClient } = require('@slack/client');
const token = 'TOKEN-VALUE-HERE';
const web = new WebClient(token);
const conversationId = 'CBG67E9JR';
web.chat.postMessage({ channel: conversationId, text: '<https://google.com|CLICKME!> *bold*', parse: 'full' })
.then((res) => {
console.log('Message sent: ', res.ts);
})
.catch(console.error);
// In one case, the parse functionality is respected. In another case, it is not respected. This is confusing!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment