Bot Framework save user data in the database by UserID - botframework

I want to save data that the user has entered in my database.
I need an ID that will be unique for all conversations with the same user rather than for a single conversation.
According to the documentation, I need to use the From.ID field from the Channel Account data.
But when I use Bot Framework Emulator and click Restart with same User ID, the ID of the user changes and what remains is the bot ID.
What field should I use to identify a user across different calls (in the same channel, of course)?
In this example, I see that the the Recipient.id identifier that the bot sends does not change.
Is this the user's unique identifier? Why is it be different from the From.ID?
Conversation 1:
Message from the bot:
{
"channelId": "emulator",
"conversation": {
"id": "202d2d60-4c7f-11e9-b1fa-8b3537dcca45|livechat"
},
"from": {
"id": "2",
"name": "Bot",
"role": "bot"
},
"id": "208f2380-4c7f-11e9-98ea-9595460a8f6e",
"inputHint": "acceptingInput",
"localTimestamp": "2019-03-22T10:47:30+02:00",
"locale": "",
"recipient": {
"id": "d4d1b5a6-1797-4d2a-b78e-257de71d3a69",
"role": "user"
},
"replyToId": "20559cf0-4c7f-11e9-98ea-9595460a8f6e",
"serviceUrl": "http://localhost:53634",
"showInInspector": true,
"text": "conversationUpdate event detected",
"timestamp": "2019-03-22T08:47:30.232Z",
"type": "message"
}
Message from the user:
{
"channelData": {
"clientActivityID": "15532445742330.iqwrgb646rq",
"state": "sent"
},
"channelId": "emulator",
"conversation": {
"id": "202d2d60-4c7f-11e9-b1fa-8b3537dcca45|livechat"
},
"entities": [
{
"requiresBotState": true,
"supportsListening": true,
"supportsTts": true,
"type": "ClientCapabilities"
}
],
"from": {
"id": "r_wg30czmqjt",
"name": "User",
"role": "user"
},
"id": "6a791af0-4c7f-11e9-98ea-9595460a8f6e",
"localTimestamp": "2019-03-22T10:49:34+02:00",
"locale": "",
"recipient": {
"id": "2",
"name": "Bot",
"role": "bot"
},
"serviceUrl": "http://localhost:53634",
"showInInspector": true,
"text": "hi",
"textFormat": "plain",
"timestamp": "2019-03-22T08:49:34.239Z",
"type": "message"
}
Conversation 2 (After Restart with same user ID):
Message from the bot:
{
"channelId": "emulator",
"conversation": {
"id": "a10fba20-4c83-11e9-b1fa-8b3537dcca45|livechat"
},
"from": {
"id": "2",
"name": "Bot",
"role": "bot"
},
"id": "a15611f0-4c83-11e9-98ea-9595460a8f6e",
"inputHint": "acceptingInput",
"localTimestamp": "2019-03-22T11:19:44+02:00",
"locale": "",
"recipient": {
"id": "d4d1b5a6-1797-4d2a-b78e-257de71d3a69",
"role": "user"
},
"replyToId": "a116e610-4c83-11e9-98ea-9595460a8f6e",
"serviceUrl": "http://localhost:53634",
"showInInspector": true,
"text": "conversationUpdate event detected",
"timestamp": "2019-03-22T09:19:44.271Z",
"type": "message"
}
Message from the user:
{
"channelData": {
"clientActivityID": "15532464069120.36lccv6nsg3",
"state": "sent"
},
"channelId": "emulator",
"conversation": {
"id": "a10fba20-4c83-11e9-b1fa-8b3537dcca45|livechat"
},
"entities": [
{
"requiresBotState": true,
"supportsListening": true,
"supportsTts": true,
"type": "ClientCapabilities"
}
],
"from": {
"id": "r_xl9pb24o5o",
"name": "User",
"role": "user"
},
"id": "aed62f90-4c83-11e9-98ea-9595460a8f6e",
"localTimestamp": "2019-03-22T11:20:06+02:00",
"locale": "",
"recipient": {
"id": "2",
"name": "Bot",
"role": "bot"
},
"serviceUrl": "http://localhost:53634",
"showInInspector": true,
"text": "hi",
"textFormat": "plain",
"timestamp": "2019-03-22T09:20:06.921Z",
"type": "message"
}

This was a bug in the Emulator, and fixed with https://github.com/Microsoft/BotFramework-Emulator/pull/1348
Please make sure you are on version >= 4.3.3:
Also, the Recipient.Id is the bot id if the message is coming from the Emulator.

Being that the bots do not track or identify a user, that part is up to you.
You will need to:
Create a "back channel" that captures Authentication of user. Give the bot access to the userid/username of the user who is interacting or having a conversation.
When the user logs in and authenticates to the application, you identify the user - retrieve this.
When the user interacts with the bot you get the conversation ID - you already have this.
Tie them together in a JSON object and store back to cloud storage, or app storage or SQL db.

Related

Google Drive API - Searching all shared file in a Drive with query

I'm trying to find out which files in a shared google drive is shared with someone outside the organisation.
That includes :
shared with a public link
shared in domain
shared to someone by his email.
Here's an example of what I have without any filtering (post formatted)
[
{
"id": "XXXXXXXXXXXXXXX",
"name": "private but shared to external people",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "john.doe#anonymous.com",
"role": "writer"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "admin#xxxxxxx.com",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "public domain",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "domain",
"role": "reader",
"domain": "xxxxxxxx.com"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "admin#xxxxxxxx.com",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "public",
"permissions": [
{
"id": "anyoneWithLink",
"type": "anyone",
"role": "reader"
},
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "admin#xxxxxxx.com",
"role": "organizer"
}
]
},
{
"id": "XXXXXXXXXXXXXXX",
"name": "private",
"permissions": [
{
"id": "XXXXXXXXXXXXXXX",
"type": "user",
"emailAddress": "admin#xxxxxx.com",
"role": "organizer"
}
]
}
]
To filter, I used the query: q: "visibility != 'limited'" but then the file
"private but shared to external people" isn't caught anymore.
So what I want is to create a query to retrieve all files that are shared and all files that are shared to any users that do not belong to the organisation.
I've already coded a manual version of that logic (this is why I can show the permissions array) but I would like to improve performances because it's really long to loop through all files to retrieves their permission and then manually check if the user email belongs to the domain or no.
Thank you :D

Accessing collections data from Google+ API

I'm using the Google Plus API, and there seems to be no information in the JSON response regarding the collection of the post. I was wondering if there was a way to access which collection a post belongs using the API data.
For example, could we use the URL given to parse the collection from the webpage? Does anyone have any idea how this could be done in a performant way?
The google+ api is a read only api and every limited it gives you access to people, activities and comments.
Activites list returns a list of all activities#resource posts by a user. try it
The only collection you can send is public. the response looks like this.
{
"kind": "plus#activity",
"etag": "\"RKS4-q7QGL10FxltAebpjqjKQR0/82jivrLU7ubQ-fwlLaXGSt3krb8\"",
"title": "",
"published": "2018-06-18T07:03:54.034Z",
"updated": "2018-06-18T07:03:54.034Z",
"id": "z13lu3vowpa5x3aws04chl2brzavs1rplos0k",
"url": "https://plus.google.com/+LindaLawton/posts/STgianNMQwU",
"actor": {
"id": "117200475532672775346",
"displayName": "Linda Lawton",
"url": "https://plus.google.com/117200475532672775346",
"image": {
"url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAl1I/UcwPajZOuN4/photo.jpg?sz=50"
},
"verification": {
"adHocVerified": "UNKNOWN_VERIFICATION_STATUS"
}
},
"verb": "post",
"object": {
"objectType": "note",
"actor": {
"verification": {
"adHocVerified": "UNKNOWN_VERIFICATION_STATUS"
}
},
"content": "",
"url": "https://plus.google.com/+LindaLawton/posts/STgianNMQwU",
"replies": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/comments"
},
"plusoners": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/people/plusoners"
},
"resharers": {
"totalItems": 0,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13lu3vowpa5x3aws04chl2brzavs1rplos0k/people/resharers"
},
"attachments": [
{
"objectType": "article",
"displayName": "leastprivilege/AspNetCoreSecuritySamples",
"content": "AspNetCoreSecuritySamples - Samples for various ASP.NET Core Security Features",
"url": "https://github.com/leastprivilege/AspNetCoreSecuritySamples",
"image": {
"url": "https://lh3.googleusercontent.com/proxy/1pdxjC-TsuF0-8yHOZKvfDOXG1pNWAIemDoW7OzrFy8pcckGqr0BTJj-TwgW9KgEuoGLJjfUKLWSCouJwTT7FjoOmZ_xURQwzz4=w506-h910",
"type": "image/jpeg",
"height": 910,
"width": 506
},
"fullImage": {
"url": "https://avatars0.githubusercontent.com/u/1454075?s=400&v=4",
"type": "image/jpeg"
}
}
]
},
"provider": {
"title": "Google+"
},
"access": {
"kind": "plus#acl",
"description": "Public",
"items": [
{
"type": "public"
}
]
}
},
the above post here is actually within one of my collections. But no were in the response does it mention the id of the collection that its in which is olLcVE
As i mentioned this is a very limited api and what you want to do is not available.

How to get proposed time using Microsoft Graph API?

When the other person declined the meeting and proposed a new time. In Outlook, you can see the proposed time.
Now I am trying to use Microsoft Graph API to get that proposed time.
For example, the original meeting date is 2018-03-08, and the other person declined and proposed a new date 2018-03-12.
I tried
GET /beta/me/messages/{messageId}=?$expand=microsoft.graph.eventMessage/event
However, I cannot find the proposed time from the result returned. How can I get it? Thanks
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users('576552d5-3bc0-42a6-a53d-bfceb405db23')/messages/$entity",
"#odata.type": "#microsoft.graph.eventMessage",
"#odata.etag": "W/\"DAAAABYAAACpTc/InBsuTYwTUBb+VIb4AADoRAyI\"",
"id": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk-iwQZRbXMgkfKtmYhBwCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAACpTc-InBsuTYwTUBb_VIb4AADnwc8mAAA=",
"createdDateTime": "2018-03-06T22:29:10Z",
"lastModifiedDateTime": "2018-03-06T22:29:11Z",
"changeKey": "DAAAABYAAACpTc/InBsuTYwTUBb+VIb4AADoRAyI",
"categories": [],
"receivedDateTime": "2018-03-06T22:29:11Z",
"sentDateTime": "2018-03-06T22:29:05Z",
"hasAttachments": false,
"internetMessageId": "<MWHPR15MB18399806CC97C61817C9A2B18BD90#MWHPR15MB1839.namprd15.prod.outlook.com>",
"subject": "New Time Proposed: Test",
"bodyPreview": "",
"importance": "normal",
"parentFolderId": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgAuAAAAAACUbnk-iwQZRbXMgkfKtmYhAQCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAAA=",
"conversationId": "AAQkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgAQAOnuCMgoRLdGs-1scw6i7EU=",
"conversationIndex": "AdO1mnWL6e4IyChEt0az/WxzDqLsRQAABO5D",
"isDeliveryReceiptRequested": null,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": "https://outlook.office365.com/owa/?ItemID=AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk%2FiwQZRbXMgkfKtmYhBwCpTc%2FInBsuTYwTUBb%2BVIb4AAAAAAEMAACpTc%2FInBsuTYwTUBb%2BVIb4AADnwc8mAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification": "focused",
"unsubscribeData": [],
"unsubscribeEnabled": false,
"meetingMessageType": "meetingDeclined",
"type": "singleInstance",
"isOutOfDate": false,
"isAllDay": false,
"isDelegated": false,
"body": {
"contentType": "html",
"content": "Hi"
},
"sender": {
"emailAddress": {
"name": "Rose",
"address": "rose#example.com"
}
},
"from": {
"emailAddress": {
"name": "Rose",
"address": "rose#example.com"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "Jack",
"address": "jack#example.com"
}
}
],
"ccRecipients": [],
"bccRecipients": [],
"replyTo": [],
"mentionsPreview": null,
"flag": {
"flagStatus": "notFlagged"
},
"startDateTime": {
"dateTime": "2018-03-08T04:00:00.0000000",
"timeZone": "UTC"
},
"endDateTime": {
"dateTime": "2018-03-08T05:00:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "Test",
"locationType": "default",
"uniqueIdType": "unknown"
},
"recurrence": null,
"event#odata.context": "https://graph.microsoft.com/beta/$metadata#users('576552d5-3bc0-42a6-a53d-bfceb405db23')/messages('AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk-iwQZRbXMgkfKtmYhBwCpTc-InBsuTYwTUBb_VIb4AAAAAAEMAACpTc-InBsuTYwTUBb_VIb4AADnwc8mAAA%3D')/microsoft.graph.eventMessage/event/$entity",
"event": {
"#odata.etag": "W/\"qU3PyJwbLk2ME1AW/lSG+AAA6EQMeA==\"",
"id": "AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk-iwQZRbXMgkfKtmYhBwCpTc-InBsuTYwTUBb_VIb4AAAAAAENAACpTc-InBsuTYwTUBb_VIb4AADnwkmiAAA=",
"createdDateTime": "2018-03-06T22:28:32.3852279Z",
"lastModifiedDateTime": "2018-03-06T22:29:11.4604154Z",
"changeKey": "qU3PyJwbLk2ME1AW/lSG+AAA6EQMeA==",
"categories": [],
"originalStartTimeZone": "Pacific Standard Time",
"originalEndTimeZone": "Pacific Standard Time",
"iCalUId": "040000008200E00074C5B7101A82E0080000000000000000000000000000000000000000310000007643616C2D5569640100000033324633333433392D433744452D344338362D393046452D44424639314131363444323900",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Test",
"bodyPreview": "Test",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADBlZTUwNTkxLWVmODgtNDVhNC1iZjhlLTdjNjA1ODZlMDI5MgBGAAAAAACUbnk%2FiwQZRbXMgkfKtmYhBwCpTc%2FInBsuTYwTUBb%2BVIb4AAAAAAENAACpTc%2FInBsuTYwTUBb%2BVIb4AADnwkmiAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "Hi"
},
"start": {
"dateTime": "2018-03-08T04:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-03-08T05:00:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "Test",
"locationType": "default",
"uniqueId": "Test",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "Test",
"locationType": "default",
"uniqueId": "Test",
"uniqueIdType": "private"
}
],
"recurrence": null,
"attendees": [
{
"type": "required",
"status": {
"response": "declined",
"time": "2018-03-06T22:29:05Z"
},
"emailAddress": {
"name": "Rose",
"address": "rose#example.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "Jack",
"address": "jack#example.com"
}
}
}
}
The API doesn't expose this information directly. The related entities just don't have the fields defined to show this information. However, the data is obviously there, you just need to know how to get to it. The answer lies in extended properties.
Basically since Graph doesn't expose these values, we need to dig into the MAPI properties that store this data. After a little digging through the Exchange server protocol docs I found PidLidAppointmentProposedStartWhole and PidLidAppointmentProposedEndWhole. We just need to translate those MAPI property definitions into the Graph extended property syntax.
From the doc, those are both in the PSETID_Appointment namespace, which uses the GUID {00062002-0000-0000-C000-000000000046}. PidLidAppointmentProposedStartWhole uses id 0x8250, and PidLidAppointmentProposedEndWhole uses id 0x8251. So those should translate to:
PidLidAppointmentProposedStartWhole: 'SystemTime {00062002-0000-0000-C000-000000000046} Id 0x8250'
PidLidAppointmentProposedEndWhole: 'SystemTime {00062002-0000-0000-C000-000000000046} Id 0x8251'
If we use those in an $expand clause as per Get singleValueLegacyExtendedProperty, we get something like:
GET /me/mailfolders/inbox/messages?$expand=singleValueExtendedProperties($filter=id eq 'SystemTime {00062002-0000-0000-C000-000000000046} Id 0x8250' or id eq 'SystemTime {00062002-0000-0000-C000-000000000046} Id 0x8251')
And the response looks something like this (other properties omitted):
{
"subject": "New Time Proposed: Let's meet",
"singleValueExtendedProperties": [
{
"id": "SystemTime {00062002-0000-0000-c000-000000000046} Id 0x8250",
"value": "2018-03-20T20:00:00Z"
},
{
"id": "SystemTime {00062002-0000-0000-c000-000000000046} Id 0x8251",
"value": "2018-03-20T21:00:00Z"
}
]
}

G Suite Account missing displayName parameter in Calendar API

I am creating an application that gets calendar events from Google Calendar using their API. I am not able to get the creator.displayName parameter for G Suite accounts, however. To rule out that it was something in my code I simply created a calendar Event from the calendar.google.com site and went to the API Explorer (https://developers.google.com/apis-explorer/#p/calendar/v3/calendar.events.list) to look at the event.
As it turns out, G Suite users don't have a displayName parameter but resources and standard Google Calendar users do.
For a G Suite Resource account I get something like:
{
"kind": "calendar#event",
"etag": "\"123456789220000\"",
"id": "<unique-ID-here>",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=unique-eid-link-here",
"created": "2018-02-27T13:00:07.000Z",
"updated": "2018-02-27T13:00:07.160Z",
"summary": "Event Name",
"creator": {
"email": "admin#gsuitedomain.com"
},
"organizer": {
"email": "gsuitedomain.com_uniqueidentifier#group.calendar.google.com",
"displayName": "A Resource Account",
"self": true
},
"start": {
"dateTime": "2018-02-27T05:52:00-08:00"
},
"end": {
"dateTime": "2018-02-27T06:00:00-08:00"
},
"iCalUID": "unique-uid-here#google.com",
"sequence": 0,
"reminders": {
"useDefault": true
}
And for a personal account I get:
{
"kind": "calendar#event",
"etag": "\"1234567890015265\"",
"id": "unique-id-here",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=unique-eid-here",
"created": "2018-02-27T13:00:04.000Z",
"updated": "2018-02-27T13:00:05.014Z",
"summary": "Event Name 2",
"creator": {
"email": "personal-gmail#gmail.com",
"displayName": "John Doe",
"self": true
},
"organizer": {
"email": "personal-gmail#gmail.com",
"displayName": "John Doe",
"self": true
},
"start": {
"dateTime": "2018-02-27T08:00:00-05:00"
},
"end": {
"dateTime": "2018-02-27T09:00:00-05:00"
},
"iCalUID": "unique-id-here#google.com",
"sequence": 0,
"reminders": {
"useDefault": true
}
}
Where the displayName is apparent under the organizer. But for the admin or any user in the GSuite I get the following:
{
"kind": "calendar#event",
"etag": "\"123459678950000\"",
"id": "unique-id-here",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=unique-eid-here",
"created": "2018-02-27T14:00:14.000Z",
"updated": "2018-02-27T14:00:24.391Z",
"summary": "Event Name 3",
"creator": {
"email": "admin#gsuitedomain.com",
"self": true
},
"organizer": {
"email": "admin#gsuitedomain.com",
"self": true
},
"start": {
"dateTime": "2018-02-27T07:30:00-08:00"
},
"end": {
"dateTime": "2018-02-27T08:00:00-08:00"
},
"iCalUID": "unique-id-here#google.com",
"sequence": 0,
"reminders": {
"useDefault": true
}
Am I missing something? Why don't G Suite users have the displayName parameter by default?
To anyone else who is struggling with this-
Individual user identity information is tied in with the Google+ profile that is created for that user. Google+ is enabled for the G Suite domain but the service has to be enabled for each user as well.
Once the G+ profile is set up the displayName will be available.

Bot Framework doesn't have username if telegram profile doesn't have full name or username

Messages delivered from Bot Framework don't have name property in from object if message was sent by user who doesn't have username and full name. For example if you delete first or last name from profile like that
Here's example of json that I get for messages sent from user that only has first name (look at from object):
{
"channelData": {
"message": {
"chat": {
"all_members_are_administrators": true,
"id": -219911672,
"title": "jlarky-dev",
"type": "group"
},
"date": 1493246056,
"from": {
"first_name": "Test",
"id": 107390199
},
"message_id": 100,
"text": "test"
},
"update_id": 66470785
},
"channelId": "telegram",
"conversation": {
"id": "-219911672",
"isGroup": true,
"name": "jlarky-dev"
},
"entities": [
{
"mentioned": {
"id": "JLarkyTestBot",
"name": "jlarky_test"
},
"text": "JLarkyTestBot",
"type": "mention"
}
],
"from": {
"id": "107390199"
},
"id": "KxBlE8JsLfg",
"recipient": {
"id": "JLarkyTestBot",
"name": "jlarky_test"
},
"serviceUrl": "https://telegram.botframework.com",
"text": "test",
"timestamp": "2017-04-26T22:34:17.4109674Z",
"type": "message"
}
Since #NilsW's comment I tested this again and it looks like from.name only exists when username of telegram profile was set (same can be looked up from channelData.message.from.username), so I guess it makes sense for it not to show username when username was not set :) and not having last_name part was not related here.

Resources