How can I start a conversation with user data like user name, user domain ID - botframework

I need to develop enhancements to an existing app which will interact with a bot developed using MS bot framework. For this, I am thinking of utilising the Direct Channel. However, I dont understand, how I can pass on user specific information from the app to the bot.
In documentation available at https://learn.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-send-activity,
It is mentioned that the payload of the REST request would be
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
Where should I pass on the user specific or sessions information like user first name, last name, email id or Login id or initiating app or location from where the user is initiating the chat or anything else here ?
Any guidance will help.

How can I start a conversation with user data like user name, user domain ID
As NicolasR pointed, it does not enable us to attach/specify user information when starting a conversation on Direct Line Channel.
how I can pass on user specific information from the app to the bot
If you’d like to send activity and pass user information (firstname, lastname etc) to your bot by using the Direct Line API, as you see in that documentation, to send an activity to the bot, the client must create an Activity object to define the activity. You can refer to the following example request to contains the user information in from field of your request JSON payload.
In my bot app code (c#), I can extract user information from Activity object using the following code snippet.
if (activity.From.Properties["firstname"] != null)
{
var fname = activity.From.Properties["firstname"].ToString();
}

Related

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

Slack integration: link slack user and user from 3rd party Web service

I have some Web Service (for example, Twitter). This service already has users, so every user has account.
I want to provide ability for user to enter something like that in slack:
/tweet "Amazing tweet sent from Slack"
And this tweet should appear at Twitter's page of this user(say, John D. with id=1).
I read something about Slack apps, so highlevel overview is the following:
I need to create a new Slack app
I need to register slash command in this app and provide backend URL which will handle all requests from slack users (like https://twitter.com/slack-integration)
When user enters /tweet "Some tweet", then the following will be sent to https://twitter.com/slack-integration:
user_id=U2147483697&user_name=SlackUser&command=/tweet&text=Some tweet
So, user_id is Slack user id. And now I need a way to link it to John D. with id=1.
Any ideas, what should I do for that?

Persistent Skype user ID across individual and group chat.

When a bot chat with a user individually or in a group, the API returns different user ids. How can I know it's the same person?
Skype user's information fields looks like the following "from": { "id": "29:1DwlGVzj.....", "name": "My Skype Name" } (and bot's id is "28:appId").
This user id is a specific to your bot, it is a hash but the way it is generated is not known (not open-source). But this id is identidical for a unique user when talking individually with the bot or inside a group conversation with the same bot.
See sample here, I just checked:
Direct message between user and bot:
Group conversation including same user and same bot:
I've hidden some characters of the id in case of... but I confirm they are exactly the same values.
See also questions around the same problems:
For more details about the different channels and the ID format: Authenticate user across channels in Microsoft bot Framework
Get Skype ID from Activity object Bot Framework V3
Getting Skype Identity In Bot Framework?

Find the address of a specific user using Microsoft bot-builder

I would like to open new conversations with users using the Microsoft Bot Builder on the Skype for Business channel. The only information I have is the user id (sip:user#domain.com)
In all the examples I could find, it is needed to save the conversation id/address of a user in a previous conversation to send a new message to this user.
How to create a new conversation as a bot to a user knowing only his id?
Thanks
Like you stated the userId is required to send a message to the user. A new conversation can be created by the framework but ultimately, you can't do anything without the userId and to obtain this the user has to contact your bot first. This is only true for channels like Skype. Other channels like E-mail just use the email address as an id. Skype uses a GUID as the id for their users. This is done so bots can't randomly add themselves to any user on Skype. Source
This doesn't mean you have to necessarily wait for the user to start a conversation. Whenever a user adds a bot to their contact list an event is send to the bot. This is the ContactRelationUpdate event. It warns the bot that a user has added the bot and the bot can then respond accordingly. Once this event is thrown you can obtain the userId from the activity and do whatever you want with it. Source

Google API - How can I get the gmail contact details page?

My application use google+ sign-up and login system.
When user click on gplus button allows my app to manage his gmail contacts.
After logged in, I can get all the gmail contacts very easily with a simple $.getJSON call.
Google response is a well structured JSON - feed and entries where I can find contacts fullname, email address, mobile number etc.
My problem is to be able to jump to the google details page of a specific contact.
Here my question: Do you know how can I do that?
I mean ... where is the contact unique identifier and how can I make a link that open the google details of that specific contact?
Thanks
Use Google+ data API instead. It returns with details of use including id of that user.
Its response is as below:
{
"kind": "plus#person",
"id": "118051310819094153327",
"displayName": "Chirag Shah",
"url": "https://plus.google.com/118051310819094153327",
"image": {
"url": "https://lh5.googleusercontent.com/-XnZDEoiF09Y/AAAAAAAAAAI/AAAAAAAAYCI/7fow4a2UTMU/photo.jpg"
}
}
Now, using that id, you can goto user details page at http://plus.google.com/your_id
for full details, see here: https://developers.google.com/+/api/#data

Resources