Slack: how to get directmessage channel name - post

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.

Related

Find YouTube user name for a channel

I am trying to use the YouTube Data API to fetch channel data for particular channels. According to the documentation, I can use list (by channel ID) or list (by YouTube username)
Search by channel ID
https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id={ChannelID}&key={APIKey}
// Get channel by YouTube username
https://youtube.googleapis.com/youtube/v3/channels?part=snippet&forUsername={Username}&key={APIKey}
The channel ID can be retrieved by going to YouTube in a browser and search for the channel by name and then when you select the channel; the channel ID is part of the URL like this:
https://www.youtube.com/channel/UCbTw29mcP12YlTt1EpUaVJw.
This particular channel is for Sean Allen and his YouTube URL is:
https://www.youtube.com/SeanAllen.
I would have thought that the YouTube username would be SeanAllen, but it is not because, when I use that term in the API request, I get 0 results.
However, in my own case, my channel ID is UCOWdR4sFkmolWkU2fg669Gg and the search by channel ID works to fetch my channel data. My YouTube URL is:
https://wwww.youtube.com/StewartLynch
and, if I use StewartLynch as the username, I can use that 2nd API request to fetch the same data.
So, my question is, how does one find the correct YouTube username for a channel? Apparently it is not what is used in the channel URL.
The issue you're raising is recurrent time and again on Stack Overflow. I myself already tackled all faces of it (just issue either of the following SO search terms: user:8327971 custom URL or user:8327971 forUsername).
The short story is as follows: don't rely much on YouTube user names.
User names are a legacy feature of the API v3: not every channel has one attached and no channel is required to have one attached. (See this official statement from Google staff from 2013-07-11.)
Here is what YouTube Data API returns for the two names -- SeanAllen and StewartLynch -- of your post:
$ python3 youtube-search.py --custom-url SeanAllen
UCbTw29mcP12YlTt1EpUaVJw
$ python3 youtube-search.py --user-name SeanAllen
UCRGhxM6u14Uv309cC0ywEqA
$ python3 youtube-search.py --custom-url StewartLynch
UCOWdR4sFkmolWkU2fg669Gg
$ python3 youtube-search.py --user-name StewartLynch
UCOWdR4sFkmolWkU2fg669Gg
As you can see, StewartLynch is both the custom URL and the user name of the channel of which ID is UCOWdR4sFkmolWkU2fg669Gg.
But, in case of SeanAllen, things are not that simple since there's a channel -- UCbTw29mcP12YlTt1EpUaVJw -- that has its custom URL set to this name; and, at the same time, there's a different channel -- UCRGhxM6u14Uv309cC0ywEqA -- that has its attached user name set to the this very same name.
This situation is very much perennial with YouTube: many channels out there have in common this property.
The final note, which closes your question:
how does one find the correct YouTube UserName for a channel?
The Channels.list API endpoint queried with the request parameter forUsername does return the correct user name of a given channel (if the respective channel has attached an user name).
The ambiguity stems from the fact that URLs of form:
https://www.youtube.com/NAME
may well represent either a channel of which user name is NAME or a channel of which custom URL is NAME. The two cases can be set apart only by the (not-completely reliable) procedure of searching for custom URLs (which is implemented already by the script youtube-search.py).
Above I make use of my public (MIT licensed) Python 3 script youtube-search.py; this script is able to search the API for custom URLs and respectively query the API for user names.
Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)

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!

List channel subscriptions returns only my channel

So, I have a request that should list my subscribers who do not have the private subscriptions option enable. My request is:
response = youtube.subscriptions().list(
part="snippet",
maxResults=50,
mySubscribers=True
).execute()
However, in items resource, every channel returned is my own channel. My channel name, ID and profile images. Is this the problem with the API or am I making a wrong request?
I also tried using the Try this API option on the documentation, but it also returns the same result.
https://developers.google.com/youtube/v3/docs/subscriptions/list
Thank you for any help you can give
According to the official docs you already quoted, you should have passed to your API call the parameter part as:
part="snippet,subscriberSnippet".
The subscriberSnippet part gives you the needed info:
subscriberSnippet (object)
The subscriberSnippet object contains basic details about the subscriber.
For what concerns the snippet part, the official doc is indeed a bit ambiguous:
snippet (object)
The snippet object contains basic details about the subscription, including its title and the channel that the user subscribed to.
Nevertheless, the info you get from part="snippet" only is correct.

How to alert a custom group in slack using incoming webhook

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

What is the purpose of each parameter in a MailChimp unsubscribe URL?

In the following URL, that unsubscribes a user from a list:
http://xxxxx.us2.list-manage.com/unsubscribe?
u=87f537bccxx35e53a1890e0d9&
id=40dcxx6cd6&
e=c4aaxx1dd6&
c=9a6xx11963
What does each parameter do?
Today I had to learn what each nondescript parameter means so that I could generate URLs for each email I send through Mandrill. It wasn't that easy to discover their meaning, but here are the one's I've come up with and how I found out what they are.
http://xxxxx.us2.list-manage.com/unsubscribe?
u=87f537bccxx35e53a1890e0d9&
id=40dcxx6cd6&
e=c4aaxx1dd6&
c=9a6xx11963
URL format:
Protocol can be http or https.
Your username comes next
In the example, us2 is the MailChimp datacenter where your account resides. That's different for each account. (https://apidocs.mailchimp.com/api/2.0/) It's good practice to specify a DC even though the documentation says that it isn't required. Specifying it will cut down on unnecessary latency.
list-manage[n].com can work with or without the number at the end of the domain, or it can have a 1 or a 2. Changing that doesn't appear to matter, but I think it has something to do with their load balancing.
/unsubscribe can also be /subscribe or /profile (The latter appears to be dependent on the "e" parameter. (See below) When you don't specify it, it states, "List member profiles cannot be updated from test campaigns or archive pages" and if you specify an invalid value, you get an error page.
u Is a unique identifier for your account. Every list on your account uses it. (See http://kb.mailchimp.com/lists/signup-forms/find-the-unsubscribe-link-for-your-list for how you can view the various URLs for your account.)
id is your list ID
e is the euid as documented on https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
c I haven't seen this one yet, but my guess is that it's the campaign ID.
Also, when you wish to prefill subscribe and unsubscribe forms, you can use the following GET params.
EMAIL Allows you to enter the subscriber's email
MERGE1 Allows you to enter the subscriber's first name
MERGE2 Allows you to enter the subscriber's last name

Resources