Get recipient of a DM message in Slack - slack

I have a Slack App that listens to message events with the appropriate user and bot scopes (The app has im:read and im:history permissions among others, on behalf of the user). The event payload looks like this:
{"client_msg_id": "...",
"type": "message",
"text": "...",
"user": "<sender id>",
"ts": "...",
"team": "...",
"blocks": [...],
"channel": "D012345678 <example direct channel id>",
"event_ts": "...",
"channel_type": "im"}
Is there a way to identify the recipient id of this message?
I have looked into conversations_members API and used the channel_id provided by the event payload. It throws a channel_not_found error. I tried a hardcoded test with an actual private channel that the user of the app is in, and it returned the list of user-ids as expected. So it seems like the issue is related to DM channels.
Tried to use the user-id instead of the channel id as this comment suggested. Didn't work either.
Any help is appreciated.
Additional info:
pip freeze | grep slack
slack-bolt==1.13.2
slack-sdk==3.16.1

For anyone who is facing the same issue, I asked the SlackBolt devs to pitch in and here's their answer. . In summary, conversation_members mentioned in the questuon is the correct starting point. But if both your user and bot tokens have im:read permissions, the priority is to the bot token. Replace it with user token and you should be fine. More elaborate answer is in the discussion link.

Related

How can a microsoft botframework bot mention a user in an adaptivecard?

Following the Schema explorer at adaptivecards.io, there is no schema available for a bot mentioning a user (and teams sending him the proper notification that he was mentioned afterwards).
See https://adaptivecards.io/explorer/ for reference.
We want to use the bot for proactive messages to our users. If a user gets mentioned in one other solution, we want to transfer that mentioning event to the teams channel conversation and leverage the ability of teams to notify the user appropriately.
Question: Is there a way to add a valid teams #mention to a channel member in a bot message using adaptivecards?
Mentioning users can be done in AdaptiveCards according to this documentation: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#mention-support-within-adaptive-cards
To include a mention in an Adaptive Card your app needs to include the following elements
<at>username</at> in the supported adaptive card elements
The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned
The mention object looks similar to this:
{
"msteams": {
"entities": [{
"type": "mention",
"text": "<at>John Doe</at>",
"mentioned": {
"id": "8:orgid:{org-ID-of-the-user}",
"name": "John Doe"
}
}]
}
}
The ID to mention a user needs to be in this format: 8:orgid:{org-ID-of-the-user}

Programmatically sending a message to a bot in Microsoft Teams

I have created a proactive bot that basically asks certain questions to a user when a user starts conversation with the bot. The bot is deployed in Microsoft Teams environment. Is there any way that i can send automated message to a bot in a channel? I know messages can be sent using powershell by utilizing webhook url exposed by a particular team or using MS Flow. But I want to mention bot (e.g. #mybothandle) in the message so the bot starts asking questions by itself than requiring the user to start the conversation (by mentioning the bot manually) but not finding the way to mention.
Your suggestions are welcome.
Basically you want to message the user directly at a specific point in time (like 24 hours later). I'm doing this in a few different bots, so it's definitely possible. The link that Wajeed has sent in the comment to your question is exactly what you need - when the user interacts with your bot, you need to save important information like the conversation id, conversation type, service url, and To and From info. You can store this, for instance, in a database, and then you can actually have a totally separate application make the call AS IF IT WAS your bot. In my bots, for example, I have the bot hosted in a normal host (e.g. Azure Website) but then have an Azure Function that sends the messages, for example, 24 hours later. It just appears to the user as if it was a message from the bot, like normal.
You will also need the Microsoft App ID and App Password for your bot, which you should have already (if not, it's in the Azure portal).
In your "sending" application, you're going to need to create an instance of Microsoft. Bot.Connector.ConnectorClient, like follows:
var Connector = new ConnectorClient(serviceUrl, microsoftAppId: credentialProvider.AppId, microsoftAppPassword: credentialProvider.Password);
You also need to "trust" the service url you're calling, like this:
MicrosoftAppCredentials.TrustServiceUrl(serviceURL);
Then you create an instance of Microsoft.Bot.Schema.Activity, set the required properties, and send it via the connector you created:
var activity = Activity.CreateMessageActivity();
activity.From = new ChannelAccount([FromId], [FromName];
activity.Recipient = new ChannelAccount([ToId], [ToName]);
activity.Conversation = new ConversationAccount(false, [ConversationType], [ConversationId]);
activity.Conversation.Id = [ConversationId];
activity.Text = "whatever you want to send from the bot...";
Connector.Conversations.SendToConversationAsync((activity as Activity)).Wait();
All the items in square braces are what you get from the initial conversation the user is having with the bot, except that the From and To are switched around (when the user sends your bot a message, the user is the FROM and your Bot is the TO, and when the bot is sending you switch them around.
Hope that helps
To all Future Visitors, Microsoft Graph API (Beta) now provides a way to send message and mention the bot/user using following endpoint:
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages
Method: POST
Body:
"body": {
"contentType": "html",
"content": "Hello World <at id=\"0\">standupbot</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "StandupBot",
"mentioned": {
"application": {
"id": "[my-bot-id]",
"displayName": "StandupBot",
"applicationIdentityType": "bot"
}
}
}
]
}
However, there is a bug that bot doesn't respond when receives the message:
Bot is not responding to #Mention when sending message using Graph API

Getting Skype to Post to a Group Conversation Via a Conversation ID

Hello Bot Framework engineers! I'll be honest here and mention straight off I'm not a developer, but I'm attempting to get my Skype Bot to work in Azure, and I've gotten most of the way there. The only thing I'd like to know at this point is how to get a ConversationID so I can send messages THROUGH the Skype bot to a group that the bot is a part of. Is that possible to get somehow?
You can get the skype conversation ID through the message. Using Ngrok, I found one which looked something like:
"conversation": {
"isGroup": true,
"id": "19:8cc9a9nnnnnnnnnnnnnnnnnnnnnnnnnn#thread.skype"
},
C# it would be something like:
turnContext.Activity.Conversation.Id

How can I get the user's first and last name by his gmail?

I am developing an application to work admin.google.com. In my application through Google_Service_Directory I got a users. But I can not understand who it is - I see only gmail. I want by gmail to get the name and surname. How can I do it?
On the Internet, I found answers to the Google Plus library. But Google Plus is closing. What are some other ways to get your first and last name by gmail?
You have a few options and they will give you similar information.
people get Google+ api.
Request:
GET https://www.googleapis.com/plus/v1/people/me
response: people.resource
"objectType": "person",
"id": "11720047553265346",
"displayName": "Linda Lawton",
"name": {
"familyName": "Lawton",
"givenName": "Linda"
Note: this call appears on the Google+ api documentation how ever this end point is not being shutdown. (waiting for feed back from google on if this is shut down or not.)
Userinfo endpoint
The second option is to call the identity server directly to the userinfo endpoint as described in OpenIDConnect requires profile scope i think
people.get people api
people.get from the people api
request
GET https://people.googleapis.com/v1/people/me?personfield=names
response
"displayName": "Linda Lawton",
"familyName": "Lawton",
"givenName": "Linda",
"displayNameLastFirst": "Lawton, Linda"
Cant search on email
Note: This will give you the information on the current logged in user. There is no way to get back the name of a persona directly by their email address. Assuming you are running an service account with domain wide delegation you may be able to use people.get with the user id of one of the users on the domain. I have not tried this

Zoho API: Get the user that is making the request

I have seen Zoho APIs give us the option to get all kinds of user information, yet I cannot find any method to fetch info about the user that is currently making the request.
OAuth2 secured API's usually offer such an endpoint, like Google or Twitter do.
In their documentation there is something that looks like it:
https://www.zohoapis.com/crm/v2/users?type=CurrentUser
But then they shatter any hope with their explanation:
CurrentUser - To get the list of current CRM users
Is there any known way achieve this?
This is the right endpoint: https://accounts.zoho.com/oauth/user/info
It requires the aaaserver.profile.READ scope.
Example Response:
{
"ZUID": 123123123123,
"First_Name": "Example",
"Last_Name": "Name",
"Display_Name": "Example Name",
"Email": "example#email.com"
}
I have tested this personally and can confirm that the text on their docs is wrong.
They say:
CurrentUser - To get the list of current CRM users
But in reality, that endpoint really does return a single user everytime, the user to whom the oauth token belongs. So it's not returning "a list of current CRM users", but rather "the currently logged in user" - exactly as you desire.
So your gut was right, and that endpoint will achieve what you are trying to do.

Resources