Is possible to send an activity to a bot from a conversation from an other direcline client? - botframework

I have a bot, a client start a conversation with it using directline 3.0.
The bot follow a waterfall flow and at one step start an external process that do something. The process, finished the task use directline to start a new connection. i would like to send a message to the bot using a specific connection as the bot receive the message and can continue the flow. Is it possible?

Yes, this is possible using proactive messages. There is no need to use direct line, specifically, to create a new connection to send an activity. In short, in your bot's you will create a new API that external services can ping. As part of the process, when the API is hit, a conversation reference is created that, in short, allows you to pass any received data as an activity to the bot. When the bot receives the activity, you can setup logic to determine what the bot does next.
There is a SO post here that addresses this issue that you can reference. Additionally, you can refer to the BotBuilder-Samples GitHub sample for additional clarification.
Hope of help!

Related

Bot Framework Composer Sending Direct Messages

I have a lot of questions about getting started. I currently have a sample bot I built in Composer that works for my teams/slack channels and works in the testing Bot Framework Emulator without issue.
I am not sure how to make the bot send a direct message/private message to a user in a channel instead of it replying directly in the channel itself. Any one have any ideas of how to accomplish this?
You can send messages from the bot to any user (or channel) by using the Azure Bot Service REST API (using the Send an HTTP Request action in Composer as described here. As you'll see in the documentation, the main limitation is that the recipient must have had a previous conversation with your bot from which you've recorded the conversationID (and activityID if you want to reply to a thread).

How to make Slack app send a private message via an incoming webhook to someone specific?

I created a Slack app that sends a series of interactive messages to a channel. In my Slack API dashboard, I see that I can create and remove hooks. Right now the hook url that I have set up in my code is the one for the Slackbot channel.
But the problem is that such a message only gets sent to me.
I want to send the Slackbot messages to Alice in situation A, and to Bob in situation B. Not just to myself, the guy who configured the app.
What's the best way to do this?
I would suggest that you should not use hooks for this. A more sane way to do this right would be via chat.postMessage Web API method which is documented here!
This is because hooks are tied to specific conversations and that approach quickly hits a wall on what it can really achieve, especially messaging different people. Once you start using the web API it's pretty simple. Just ask for the scope during app installation (remember to add that scope in your dashboard), subscribe to the event in your API dashboard and then you are good to go.
Everytime you send a message via that method, Slack will send you a payload which you can use for testing and logging etc.
You can see all the different ways to message programmatically inside Slack here.

Sending a message to users as a bot in bot channel of Microsoft Teams using the Graph API

I have created a bot by following the steps mentioned in the doc.I have authenticated user using oauth 2.0 (auth code grant) as mentioned in the doc and in reverse I got a access token. But when I send message to channel in the teams using (/teams/{id}/channels/{id}/messages) API the message was sent on behalf of me. But I want my bot as the sender of message. Here is the image of the message that I have sent using the above API. and is there any way to send direct message to user as a bot?
Instead of using the Graph, there's another approach using the Bot Framework itself, to send a message to a team channel, a group chat, or a 1-1 conversation. The code doesn't even need to live inside the bot itself, it just needs to leverage the bot framework under the covers (for example, I have several Azure Functions that pro-actively message users). This idea is called "Proactive messaging" and you can read more about it in the docs here.
You do need to get certain fields when the user first installs the bot though, or any time the bot receives a message. I've described that more at Programmatically sending a message to a bot in Microsoft Teams. You haven't said what language you're using, but there are examples for a bunch of them - I can send you links if you let me know what you're using.

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!

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