I am working with Slack API recently and my motive is to send a channel wide message at a certain time by calling a web hook provided by Slack Incoming Web hooks.
I created a web hook and got code from Slack as below
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <#G5CERWGRG|hep_test>", "link_names" : 1}' HOOK_URL
But i cannot notify all in the team by just sending #channel in the message as like we do in normal slack channel chat. If i send #channel in the curl message, it shows as text message in chat, and not as #channel link.
I even tried sending slack channel id <#G5CERWGRG|hep_test>, as shown in the above curl request. But the message posted isn't notifying all in the group.
Note : I want to keep my channel notification preference as it is (Notify only on mentions)
Note
The correct syntax for sending #channel messages is <!channel>.
So the correct curl command for your example should read:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <!channel>", "link_names" : 1}' HOOK_URL
See also here for reference in the official documentation. You can also try this out in the message builder.
Note that in order to overwrite the default channel for your webhook you need to also add the additional property channel with the channel name. That will however only work for webhooks created through custom integration, not for webhooks created by Slack apps.
See here for an example on how to overwrite the channel name.
For anyone else struggling to get this working, if you are using blocks, it looks like you need to have the <!channel> in the block content, and not in the text content.
The text key shows up in the notification and doesn't allow formatting, while the blocks do.
The chat.scheduleMessage method (https://api.slack.com/methods/chat.scheduleMessage) will accomplish the same thing.
You can use "link_names": True in your payload and use #name :
slack_data = {
'text': 'Hi #user, this is for you',
"icon_emoji": self._icon,
"username": sender,
"link_names": True
}
Related
I am writing a Slack integration that can boot certain users out of public channels when certain conditions are met. I have added several OAuth scopes to the bot token, including the following:
channels:history
channels:manage
channels:read
chat:write
chat:write.public
groups:write
im:write
mpim:write
users:read
I am writing my bot in Python using the slack-bolt library and asyncio. However when I try to invoke this code:
await app.client.conversations_kick(channel=channel_id, user=user_id)
I get the following error:
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/conversations.kick)
The server responded with: {'ok': False, 'error': 'channel_not_found'}
I know for a fact that both the channel_id and user_id arguments I'm passing in are valid. The channel ID I'm using is the string C01PAE3DB0A. I know it is valid because I can use the very same value for channel_id in the following API call:
response = await app.client.conversations_info(channel=channel_id)
And when I call conversations_info like that I get all of the information about my channel. (The same is true for calling users_info with the user_id - it returns successfully.) So why is that when I pass my valid channel_id parameter to conversations_kick I consistently receive this channel_not_found error? What am I missing?
So I got in touch directly with Slack support about this and they confirmed that there is a bug on their end. Specifically, the bug is that I should have received a restricted_action error response instead of a channel_not_found response. Apparently this is a known issue that is on their backlog.
The reason the API call would (try to) return this restricted_action error is simply because there is a workspace setting that, by default, prevents non-admins from kicking people out of public channels. Furthermore, this setting can only be changed by the workspace owner - one tier above admins.
But assuming you are the owner of the Slack workspace, you simply have to log into the Settings & Permissions page, which should look something like this:
And then you have to change the setting labeled "People who can remove members from public channels" from "Workspace admins and owners only (default)" to "Everyone, except guests."
Once I made that change, my API calls started succeeding.
This is how my dialplan (/etc/asterisk/extensions.conf) looks like:
[default]
exten => _X.,1,NoOp(New call from ${EXTEN} ! )
same => n,NoOp( The header X-Twilio-CallSid = ${SIP_HEADER(X-Twilio-CallSid)})
same => Dial(SIP/SomePeer)
... etc
Thanks to the function SIP_HEADER I am able to get the id of the call that my provider sends me. This is the first packet I capture using WireShark:
In other words ${SIP_HEADER(X-Twilio-CallSid)} = ACbccc967c48dda15d8d1c9b34961d19a0
This works great for incoming calls. Now my problem is for outgoing calls. The sip header X-Twilio-CallSid does not exists until the call is answered. How can I read that header once the call is answered? I have tried placing ${SIP_HEADER(X-Twilio-CallSid)} once the call hangs up. Analyzing the traffic through Wireshark that header appears after the INVITE request.
SIP_HEADER function work only for ONE packet - inbound FIRST invite message.
You have write your own function using c/c++ or use some other soft like homer/sipcapture.
I haven't tested this, but according to the docs, you can write a post-answer handler as either a macro (using M()) or a GoSub (using U()):
[outbound-twilio]
exten => _X.,1,Dial(SIP/${EXTEN}#twilio-trunk,,M(post-answer))
[macro-post-answer]
exten => s,1,Verbose("Answer header shows ${SIP_HEADER(X-Twilio-CallSid)}")
same => s,n,Return()
I'm not sure if this will be any different, since the INVITE transaction may only track the initial request, and not the response, even when we execute it from the other channel. You may also want to look into switching to chan_pjsip, which has PJSIP_HEADER:
PJSIP_HEADER allows you to read specific SIP headers from the inbound PJSIP channel as well as write(add, update, remove) headers on the outbound channel. One exception is that you can read headers that you have already added on the outbound channel
Perhaps this is implemented differently than chan_sip's SIP_HEADER function?
Also, more docs on Macros from the book.
My question is very similar to this one,
I want to get channel id using channel custom name.
The answer on the question mentioned above which is:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}
doesn't work on small channels, for ex. when I run it with this channel: https://www.youtube.com/AnnaShearerfashionfettish it returns nothing.
It's very easy, using curl and grep.
Command
channel_name='DOVASYNDROMEYouTubeOfficial' #change this as you like
curl --silent "https://www.youtube.com/c/${channel_name}/videos" |\
grep -o -P '(?<=canonical" href="https://www.youtube.com/channel/)[^"]*'
Output
UCq15_9MvmxT1r2-LLjtkokg
I didn't find a direct way to do this. I did a GET request to get the channel page HTML and parse it.
I used Jsoup to parse the html response.
val doc = Jsoup.parseBodyFragment(body)
val links = doc.select("link[rel=canonical]")
val channelUrl = links.first().attributes().get("href")
Did you try
https://www.googleapis.com/youtube/v3/channels?part=snippetforUsername={username}&key={your key}
Remember to change {your key} to your API key, and {username} to the desired username.
I'm using the slack-notifier gem to send notifications to my slack channel.
notifier = Slack::Notifier.new "https://hooks.slack.com/services/ABC1234567890"
notifier.ping "Text <#user1>"
That is the general setup in rails.
When I send to #user1 (my coworker), everything is OK.
But if I send it to #user2 (myself), text is displayed without mention creating notification or being a clickable link.
Also, if i send it to a usergroup, #my_team text is same above.
I have also tried !my_team and <#user1|user1> . The output to the slack channel looks like <my_team> or #user1. So it appears it is not parsing correctly.
Why could this be happening?
(Moving my comment to an answer.)
I'd suggest this:
notifier.ping "Text #user1", parse: "full"
The "full" parse mode means you'll get automatic linking of #username, #channelname, etc., just like you get when typing into the Slack website/clients.
I want to know that how I can send formated messages through twilio .net api
Using .net library
So my requirements are like. also can I make use of html tags?
TwilioRestClient client;
client = new TwilioRestClient(accountSID, authToken);
string msg="Hi dalvir,
//line break
Welcome to my website.....
....
//line break
Thanks
<b>Support Team<b>
";
// Send an SMS message.
Message result = client.SendMessage(....);
Use %0a
For example:
"Body=Here is my first line%0aHere is my second line"
When sending outbound messages via the REST API without using a helper library, it is best to encode a new line character using URL encoding. In URL encoding, a new line character is encoded as %0a.
Here’s an example cURL script:
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
-d "To=+13105551234" \
-d "From=+12125555555" \
-d "Body=Here is my first line%0aHere is my second line" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
This example sends an outbound message from the sender (212) 555-1234 (+12125551234) to the recipient at (310) 555-5555 (+13105555555), and includes the following message:
Here is my first line
Here is my second line
Twilio developer evangelist here.
You can absolutely add line breaks in SMS messages. You can do so in the way you would normally include line breaks within .NET.
SMS messages do not support HTML tags though, so making text bold is not possible.