MS Botframework Directline v3.0 messageIds repeating - how to make them unique? - botframework

We have developed Windows Service that sends messages to Directline API 3.0. Besides creating new conversation it uses also reconnect if the conversation was idle until the token expired.
Lately, we observed duplicated message Ids for messages with different content - see an example of 3 such message Ids from one conversation:
EfNI0i891Ic9T0UyK3QbOP|0000001 2017-10-20 08:44:10.133
EfNI0i891Ic9T0UyK3QbOP|0000001 2017-10-23 15:31:20.000
EfNI0i891Ic9T0UyK3QbOP|0000001 2017-10-25 21:33:01.897
It looks like the numbering was reset at random time even that the highest message Id of the whole conversation was
EfNI0i891Ic9T0UyK3QbOP|0000233
Is there some built-in mechanism, 3rd party component or known approach to control creating of message Ids or using "alternative-message-Ids" so that we can make them unique?

Related

Time out, Image send, Email track adding to bot framework composer

I have developed a chatbot for IT Support team in our company, running on MS Teams using Bot Framework Composer. I have integrated it with Azure logic apps to send emails to IT Support team.
I want to know how to;
Get user's email address in MS Teams (We can get user's name using ${turn.activity.from.name} telemetry track event)
Set a timeout period
Send a Image to using HTTP request in JSON format (Then users can upload the screenshot of their issue)
Yes, you can get the user's email address in MS teams by making fetching the roster or user profile or make use of get single member detail from this documentation.
Not sure if you want to restart a conversation or track the last time a message was received from a user, but you can refer to Expire a conversation documentation to get started with.
MS Teams makes use of webhooks to integrate with external apps and makes use of Standard HTTP message exchange feature where responses appear in the same chain as the original request message and can include any bot framework message content, for example, rich text, images, cards, and emojis.

How to find chat conversation with bot

we are working on MS Bot Framework bot. We are integrating with directline and MS teams. In certain cases we need to download conversation history. Within directline we are using standard DL endpoints to retrieve the conversation. However these are not available for teams channel. Therefore we are trying to get chat messages using Graph API by using
/me/chats/{id}/messages
And here's our issue - to get the chat ID we are trying to iterate through chats returned by
/me/chats
And then look up conversation members by
/me/chats/{id}/members
However chat with Bot contains only user and not the bot so it appears it is a single member chat. As workaround we always sort chats by last updated timestamp descending and assuming first single member conversation is the one we are looking for however this is tricky and unreliable and also very slow some times. Is there some better way to get conversation history from MS teams channel?
Using Graph API, you can access information related to channels in Microsoft Teams. You can refer to list channel messages which retrieves the list of messages (without the replies) in a channel of a team. If you want to get the replies for the message, then you need to call list message replies or get message reply API.
GET /teams/{id}/channels/{id}/messages
One more way is to subscribe to the channel using change notifications API which makes you get all the messages of the channel to the notification endpoint.

How to get message events published on a Web API endpoint and feed it to bot framework v4 (C#, .Net Core Bot)?

I am using a third party API to provide Agent Handover (human chat) capabilities to my v4 based bot. The API requires a call back hook/ endpoint where it can send the messages/events back from the agent, and I have to get messages from it and display to users. When ever a new chat session is established a new session id is generated. And thus Session Id is passed back in all messages and events. Essentially they are sending events as Fire&Forget with a retry on failure.
For now I had implemented an eventstore (in Cosmos dB) to store events/messages and then poll Cosmos periodically display message back to user and mark them processed.
Is there any way to make it more real time or pub-sub kind of analogy?
I would like to know if some one have already implemented scenario like this. What should be the way to respond the incoming messages from agent to bot user.
Please suggest.
I would recommend creating a client using the Direct Line API to handle routing messages between the third party agent handover and the bot. Then in the bot you can pair the third party Direct Line conversation references with the user's conversation reference to forward the messages accordingly with proactive messages. For more details take a look at this Stack Overflow question.
Hope this helps!

MS Bot framework | DirectLine Api | Message Ids format is inconsistent

Same question: https://github.com/Microsoft/BotBuilder/issues/2170, just hoping for a quick response.
So we've got a web interface which uses https://www.npmjs.com/package/botframework-directlinejs (works really well) and we use the fact that messages returned via directline (bot and user msgs) have a messageId of the format "G0SRNz7iwTiLehjQsXk3tI|0000001", "G0SRNz7iwTiLehjQsXk3tI|0000002" etc to sort on the sent and received ones on our FE.
However... Messages (Activities) in the bot code itself have a messageId of the format of a GUID. Even if you got to that point in code from a request via directline.
So my question is: does directline have some sort of interception and enrichment of the messages (ids) on their side before returning to the user? Why then do these messages not have the same ID in our bot code itself?
Reason I'm asking is, we broadcast messages to a separate 'admin-console' via signalR. But the message has a GUID id. But the message had a directline id on the webchat side.
You can imagine how this mucks with sorting messages in their correct order. Especially as the timestamp on the messages is not reliable - messages are frequently in the wrong order.
Any feedback very much appreciated.

Multi-Tenant Bot with Unique Channel for every customer

We are building a bot which would require each of our customers to have their own SMS channel (unique phone number for them). From everything we can tell with the documentation of the bot framework is there is no way to do that. We want each of our customers to be able to add the bot to their own SMS number through twilio. Is this possible?
From everything we can tell with the documentation of the bot framework is there is no way to do that.
Yes you're right.
We want each of our customers to be able to add the bot to their own SMS number through twilio. Is this possible?
No, actually it's not possible :)
Shortly, BotFramework consist of three parts :
your bot logic which is a Web API service that exposes an endpoint
the channels (Skype, Facebook messenger, SMS etc)
the bot connector, where you create your bot by specifing the endpoint and one or multiple diiferent channels that the bot can use for conversations.
Because each channel can be associate only one time per endpoint hence per bot then you can't do multitenancy through the bot connector.
One solution is to create the multitenancy through the Web API service side by creating an endpoint for each customer. Maintenanbility will be difficult because of multiple endpoints you'll end up with the same number of bots into the bot director to manage. Each bot wil be associate to your customer number.
Updates: (I didn't test it but I'm pretty sure it can work)
Another solution is to use DirectLine channel and its Rest API that it exposes. If you opt for this solution it means that you will need to do a lot of things to make that work correctly after creating Direct Line channel:
you must create a client application to communicate with Direct Line channel through its REST API.
each customer can have their own number that you manage through Twilio
each message that a customer send using their SMS number and received via Twilio should trigger a call to the service of your client application
your client application will start a new conversation with Direct Line channel when a SMS is received.
each conversation started by your client application must take care about the SMS number who started the conversation by saving the state. Bot data per conversation and per user can help a lot.
when you receive a reply from the Direct Line Channel, your client application read the SMS number stored into the bot data and use this number to answer to the associated customer.
Hope it helps.
You can definitely do this.
You implement ICredentialProvider which is responsible for looking up appPassword by AppId and validating that the password is correct. This means you can have a database of bot AppId/Passwords that one endpoint services, and you look up the appid/secret and validate calls.
[ BotAuthentication(CredentialProviderType=typeof(SimpleCredentialProvider))]
Here is a simple sample implementation
https://docs.botframework.com/en-us/csharp/builder/sdkreference/d3/dde/_credential_provider_8cs_source.html

Resources