Slack API: Send a message verbatim (escaping asterisks, colons) - slack-api

I'm using the Slack JS SDK's chat.postMessage call to post messages to a Slack channel. I'm forwarded text from another source, and I'd like for that text to be posted verbatim.
But I can't figure out how to get Slack to not interpret *, _, and :.
I've tried passing in mrkdwn: false and parse: 'full', but the messages always seem to come out the same:
const slackClient = new slack.WebClient(slackApiToken);
await slackClient.chat.postMessage({
channel: targetChannel,
text: '*hello* _bye_ :smile:',
});
await slackClient.chat.postMessage({
channel: targetChannel,
text: '*hello* _bye_ :smile:',
parse: 'full',
});
await slackClient.chat.postMessage({
channel: targetChannel,
text: '*hello* _bye_ :smile:',
mkrdwn: false,
});
What I want to see in the Slack app:
*hello* _bye_ :smile:
What I see in the Slack app (for all three chat.postMessage calls):
hello bye 😄
Is there a way to get Slack to not interpret those characters as being special?
Note: I do not want to use a inline code or code block formatting for my message. I just want it to appear in plain text.

Instead of using text parameter, you can use blocks parameter to send your 'plain text'
https://api.slack.com/methods/chat.postMessage#blocks_and_attachments
Example:
await slackClient.chat.postMessage({
channel: targetChannel,
blocks : [{
type: 'section',
text: {
type: 'plain_text',
text: '*This* is a _plain_ text section block. :smile:',
emoji: false
}
}]
});

Looks like this behaviour is a known bug with chat.postMessage. I'd recommend reporting this to feedback#slack.com so that the team can get the bug prioritized.

Related

SendInBlue trackEvent returns 204 but does not show event in the console

I am trying to send an event using the SendInBlue API here.
When I send the event, it returns a 204 correctly - but I am not getting any events here and I have created an automation flow which is triggered by the event, and it does not send.
const axios = require("axios");
const url = 'https://in-automate.sendinblue.com/api/v2/trackEvent';
(async() => {
try {
const event = await axios.post(
url,
JSON.stringify( {
email: 'myemail#emailprovider.co',
event: 'USER_SUBSCRIBED'
}),
{
Accept: 'application/json',
'Content-Type': 'application/json',
'ma-key': 'xkeysib-MY_v3_API_KEY'
},
);
console.log(event);
} catch (err) {
console.log(JSON.stringify(err))
}
})();
Is there a way I can see the events from this call coming in on the console?
The ma-key is not the same that API KEY. You should use the ma-key instead your current API for the automatization key.
After a couple of mails and a phone call, i figured out where is the ma-key:
You should login at send inblue. Click on Automatization (top menu). Click on Config (left tab bar). Click on something like 'see tracking code'. Then, you see a JS code. In this code, there is a key on it. This is your key.
My panel is in Spanish so maybe the words are not the same. Cheers.
As far as I know you can't really see the events in the console.
If you just want to make sure it's working you can
go to automation
start a workflow
Select a trigger: Website activities => An event happens
If you can select your event it means it worked.
Sendinblue is more a marketing automation tool and not an event analytics. So I'm not surprised you can't see the event in the GUI. If you want to see the events, try something like Mixpanel.
As #hector said pay attention to the API key. you're using the V3 campaigns (emails, contacts...) key. The tracking API is different.
Also, if you want to add event data, apparently you absolutely need to add a random unique ID. I struggled to find this as their docs are not super clear about it. So the body should look like something like this:
body: jsonEncode(<String, dynamic>{
'eventdata': {
id:"123456",
data: {
event_data1: value1,
event_data2: value2,
}
}
'email': example#mail.com,
'event': eventName
}),

Why is my slack app posting only ephemeral messages? [duplicate]

Using Serverless and NodeJS, I have a Slack command set up like:
/myCommand doStuff
When I type /myCommand doStuff, the Slack output does this:
/myCommand doStuff
The content of the actual response I want shown goes here.
What I want to do is only have this:
The content of the actual response I want shown goes here.
without the /myCommand doStuff getting echoed.
How do I prevent that from happening?
Update - adding some code
Here's the actual command:
module.exports = () => {
return new Promise(function(fulfill) {
fulfill({
response_type: 'in_channel',
text: 'some testing text
});
});
};
Here's the handler:
module.exports.handler = (event, context, callback) => {
var response = {
statusCode: 200,
body: JSON.stringify(myCommand()),
};
callback(null, response);
};
When you are replying with
"response_type": "in_channel"
the reply is visible to all users in a channel and it will always copy the command back into the channel. This can not be turned off.
When you are replying with
"response_type": "ephemeral"
it is only visible to the user and the command will not be copied back. That is also the default, so you must be using in_channel in your script.
See here for the official documentation on that topic.

Twilio Studio: Forward SMS conversation log to email

I'm using SMS studio do have a quick chat bot conversation with inbound SMS messages, and would like to forward the conversation log to email after it's complete. I've written a function that uses the SendGrid API to forward SMSes to email. It works independently - ie, if I configure the phone number to run the function immediately as a text comes in, it will email that single SMS input.
However, I'd like to add the function to the end of of Twilio Studio flow, so that it emails the entire log of the conversation to me, once it's over. Once I append the function to the end of the studio flow, it stops working, and I get a failure notice.
Here's the code in the function:
const got = require('got');
exports.handler = function(context, event, callback)
{
const requestBody = {
personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
from: { email: context.FROM_EMAIL_ADDRESS },
subject: `New SMS message from: ${event.From}`,
content: [
{
type: 'text/plain',
value: event.Body
}
]
}
got.post('https://api.sendgrid.com/v3/mail/send', {
headers: {
Authorization: `Bearer ${context.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse();
callback(null, twiml);
})
.catch(err => {
callback(err);
});
};`
Here's the error the debugger returns, if I make this function the last step in a Twilio studio flow:
Error - 81017
Error on Twilio Function response
There was an error in the response back from a Twilio Function attached to the Studio flow.
Possible Causes
Your Function timed out before responding
Your Function returned an error response
Possible Solutions
Your Function must contain a callback.
Make sure you place the Function callback callback(err, response) is placed correctly in your Function code.
If you are using a JavaScript promise, make sure the callback is called in both success and catch blocks.
Your Function responded with an error.
I'm having a hard time figuring out what the error is. Does anyone have any tips?
Thanks!
Jarod from Twilio. I actually wrote an app very similar to this. Code looks good to me. Often when people encounter an error of this nature it is coming from the SendGrid promise. Here are two tips:
You can actually log errors and view responses from the function if you leave the function open while testing it. The logs will be at the bottom. These usually have more information.
Check that you are using an outbound email address that has been whitelisted on your SendGrid account Whitelabel - Sendgrid
Make sure you have added your environment variables to your Functions config. Twilio Functions Configuration - Console
Hope that helps! If not feel free to email support#twilio.com with more questions.

setting 'replace_original' to false while responding to Slack message action request doesn't work

Background:
I am using the python slack API (slackclient) to build an iterative sequence of data-gathering actions in ephemeral messages.
The core of this works fine. After processing the incoming request that contains the user's interaction with a set of message buttons (or menus), I respond immediately with a JSON body, as described in the "Responding right away" section of the official slack docs.
The problem:
Every response replaces the preceding message+attachments. In many cases, this is what I want, but there are situations where I want to add a response rather than replace the previous message.
Per the slack docs,setting replace_original to false should do just that. But the following code, snipped from my handling of a simple button click (for example), replaces the original button (and the text message to which it was attached):
r = {
'response_type': 'ephemeral',
'text': 'foo',
'replace_original': 'false'
}
log.debug("Returning: {}".format(json.dumps(r)))
resp = Response(response=json.dumps(r),
mimetype="application/json",
status=200)
return resp
I have tried this with and without the delete_original and response_type fields, with no change.
In short, it appears that in this case the replace_original field isn't doing anything at all; behavior is always as if it were set to 'true'.
I feel like I must be missing something here - any help is greatly appreciated.
Simple solution here: the slack API is expecting a boolean, not a string. So 'replace_original': 'false' in the above snippet ends up as {"response_type": "ephemeral", "text": "foo", "replace_original": "false"} after the json.dumps() call, which is invalid.
Instead, setting 'replace_original': False becomes {"response_type": "ephemeral", "text": "foo", "replace_original": false}, which then has the expected behavior

Slack slash command response_type ephemeral are sent to the entire channel

Ephemeral messages are supposed to be only visible to the user that issued the command. However, in my experience, it's sent to the entire channel.
Am I missing anything?
According to Slack Slash commands documentation, the only attribute needed is to set response_type to ephemeral in the response of Node.js app.
The code in my app looks like this:
var t = {
"response_type": "ephemeral",
"text": "How to use /please"
}
request({
uri: uri,
headers: {
'content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify(t)
}, function (error, response, body) {
return res.status(200).end();
});
Ephemeral messages are only supported in slash commands currently. From your screen capture it looks like you're sending your payload to an incoming webhook. Unfortunately, I can't find the wiki that backs this up, but here's another post with a similar answer: Slack API "attachments" not showing

Resources