How to alert a custom group in slack using incoming webhook - slack-api

I was trying to alert a custom group using incoming webhook in slack.I can able to alert user using <#user>, but with group any of the following format is not working
<!cgroup>
<#cgroup>
What i am missing here. Thanks in advance.

I got this working by adding a link_names attribute to my JSON payload. For example, POSTing this to my Slack hook URL:
{
"text": "#myusergroup Hello",
"link_names": 1
}
Caused users in #myusergroup to be notified by the message.

From Slack documentation.
For paid account there is an additional command for User Groups that
follows the format <!subteam^ID|handle>. (subteam is literal text. ID
and handle are replaced with the details of the group.) These indicate
a User Group message, and should cause a notification to be displayed
by the client. User Group IDs can be determined from the
usergroups.list API endpoint. For example, if you have a User Group
named happy-peeps with ID of S012345, then you would use the command
<!subteam^S012345|happy-peeps> to mention that user group in a
message.
It is working great

Related

Client.getConversationByUniqueName and Client.getConversationBySid cannot find conversations created by other users

Note: I'm using #twilio/conversations version 1.1.0 in node project. I'm transitioning from using Programmable Chat to Conversations.
I'm seeing calls to Client.getConversationByUniqueName and Client.getConversationBySid are not returning existing channels that were created by other users.
Example:
User 'A' (with its own unique identity and token) successfully created conversation 'myConvo1'using the following code:
client.createConversation({
uniqueName: 'myConvo1',
friendlyName: 'myConvo1',
});
User 'B' (with its own unique identity and token) cannot find that conversation using: Client.getConversationByUniqueName('myConvo1') OR Client.getConversationBySid(sid) (just passing in the sid I get from the initial createConversation call).
 
I see these errors respectively:
Not Found  at ​​​Upstream.actualSend​​​
​./node_modules/#twilio/conversations/node_modules/twilsock/lib/services/upstream.js:135
Conversation with SID CHc4565e40a32f4bffaf490bae2cff45db is not found. 
at ​​​conversations.syncListRead.promise.then.then.conversation​​​ ​./node_modules/#twilio/conversations/lib/client.js:283
However, I can access this conversation fine with the same functions if I'm using User A's token/identity.
Also, when I call this from User B's Client:
client.createConversation({
uniqueName: 'myConvo1',
friendlyName: 'myConvo1',
});
I get this error: Conversation with provided unique name already exists. So all of this leads me to believe the conversation is out there, but it's just not available for other users to join.
Note 2: I've been referencing the docs below. I don't see any explicit examples on how to find and join channels, so I may be missing something or approaching this wrong.
https://media.twiliocdn.com/sdk/js/conversations/releases/1.1.0/docs/Client.html
https://www.twilio.com/docs/conversations
Could this be the reason, where Twilio Conversations only supports private channels, not public channels like Programmable Chat?
Public vs. Private Channel Use Cases with Twilio Programmable Chat
Migrating to Conversations from Programmable Chat
I created multiple Service ID's and using one specific(XXXX-Chat-Dev) Chat Service ID, but application took the Default Chat Service ID which I didn't mentioned in backend.
Fixed by deleting the Default Chat Service ID in Twilio.
Cheers!

Zapier - Zap, How to call an Action on a list one by one

I'm configuring a zap which does the following:
Get a list of emails from an API endpoint.
Subscribe each record to Mailchimp
My problem here is that the subscriber email takes in a list of emails and this returns the following error message:
Bargle. We hit an error creating a subscriber. :-( Error: Invalid
Resource - Please provide a valid email address.
This is because Mailchimp aparently doesn't allow multple subscriptions in one single form.
So my question is, is there a way to perform an action per element in the list ?
Some sort of
emailList.foreach(function(email){
performAction(email);
})
Note that I cannot use the cli, is this possible with some sort of funnel action in zapier or maybe using the scrpting ?
Thanks
David here, from the Zapier Platform team.
By default, when a trigger returns a top-level list of objects, subsequent actions occur for each. I'm not sure what type of trigger you're working with, but make sure it returns an object like this:
return [{email: 'email1#gmail.com'}, {email: 'email2#gmail.com'}, {email: 'email3#gmail.com'}]
and it should work as expected.

Can you upload a file to the Slack API using files.upload as a different user?

I'm trying to find a way to have an application post a text snippet to our support channel through the Slack API. Using the files.upload method, I can create a text snippet and share it with the channel, but the post appears to come from me (because the token used to authenticate the request is mine).
I'm looking for a way to do this, but make it appear with a custom user name and icon, like you can with the chat.postMessage method's username and icon_url parameters. Is there a way to achieve this?
There are two ways.
Way 1. - If you only want to upload in a channel and don't need to listen to any conversation, then you can use incoming-webhooks. And then override the username and icon. Read "Customizing your username and icon" in Here.
Way 2 - You can create a bot user and let the bot user type post this message for you. I guess right now you are using test tokens generated by Slack so you are getting your name only. But if you use bot-user then you can use custom Name and icon_url for your bot.
I hope this answers your question.
Yes, as #Abhinav Rai suggested, you need have bot. Slack support just answered me the same question.
To upload files as a bot you'll need to create an associated 'bot user' and post the file using the bot's token: https://api.slack.com/bot-users — all files must be owned by a user account and the bot user will fill this requirement.
There is a way 3 which uses the username function from chat.postMessage function. Follow this -
import slack
import json
import os
def pureimg(data1):
data1 = '[{"text": "", "image_url": "'+data1+'"}]'
data1 = [json.loads(data1[1:-1])]
return data1
#This function will make the image url to correct format.
slacker = slack.WebClient(token='your-token-here')
payoff=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'filename.png')
#It gives cross OS compatibility on filepath.
response=slacker.files_upload(channel='#theta',file=payoff)
payoff=response['file']['permalink']
#First We upload the local file to Slack and fetch permalink.
#If you do not have any local file just put the external image URL in the payoff.
response=slacker.chat_postMessage(channel='#channel_name', text="Sample Text", username='Bot name', attachments=pureimg(payoff), icon_emoji=':emoji:')
#Then, We post to Slack Channel as a bot!

How to get full name of specific Subreddit of Reddit

Presently, I am working on Reddit app. A user can subscribe or unsubscribe from my app which will reflect to the respective account as well.
I am using ReddKit.
Now, I am stuck in getting a subreddit Full name field which is required to subscribe or unsubscribe by calling subscribeToSubredditWithFullName method. But, I am not able to extract Full Name from the response as an identifier error is being returned.
Response = "RKSubreddit: 0x7******60, full name: t5_***eq, name: politics"
Can anybody help in getting the Full Name of a subreddit?
Is there any other way to subscribe to a subreddit ?
After working on Reddkit, I found the answer that we can call "linksInSubredditWithName" method and if we need sub-reddit "full name" then it will be available in RKLink.h which will be accessible by an object of RKLink.

Slack: how to get directmessage channel name

I am creating a slack slash command and I want to know the username of the channel I am executing the command in.
So for example I have a colleague called #steve, I am directly chatting with steve and I execute the command:
/mycommand
when I check back on my application, I see that the POST request only got these values
[
(u'user_id', u'U03NKXXXX'),
(u'channel_id', u'D03QBXXXX'),
(u'text', u''), (u'response_url', u'https://hooks.slack.com/commands/T03ARXXXX/3804397XXXX/nGUTg4zpQrMrRR07scI6XXXX'),
(u'team_id', u'T03ARXXXX'),
(u'channel_name', u'directmessage'),
(u'token', u'XXXXXXXXXXXXXXXXXXX'),
(u'command', u'/mycommand'),
(u'team_domain', u'myteam'),
(u'user_name', u'myusername')
]
I was expecting directmessage to be the name of user (steve on my example), so how can I get the target channel username?
In theory you can take the channel ID you received from the slash request and get the full information of the current channel with conversations.info, which would include the channel owner of a direct message conversation.
However, due to Slack's security architecture your token needs to have access to that direct channel. And it will only have access if it belongs to one of the two participant of that direct message channel.
So unless your app has tokens from every user the best you can do is take the user ID from the Slash command, which must come from one of the two participants of a direct message.

Resources