Can I call a Microsoft BotBuilder like calling a function? - botframework

I am trying to build a bot and use it within a chat app. I think Microsoft Bot Builder is the one for me.
I looked into its documentations and tried them in the emulator.
I noticed that in these examples, you send texts to the bot either using
"consoleconnector" or "chatconnector", as the example shows.
server.post('/api/messages', connector.listen());
// Receive messages from the user and respond by echoing each message
back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
});
I don't want a new endpoint. I want to call the bot like calling a function: give the incoming message from a user and the function returns bot's response.
Is it possible? If yes, please tell me how to do it.
If it is not possible, then only way is to call it as a rest API as shown above.
In this case, do i still need "MICROSOFT_APP_ID" and "MICROSOFT_APP_PASSWORD"?
Note that, I don't want to deploy the bot to azure or aws now. I want to use it local.
Could anyone help me explain these? Thanks in advance!

The Bot Framework is built to function as an API - it takes a request and sends a response. The framework doesn't provide a callback or promise to capture the response so this approach simply wouldn't work. Take a look at the DirectLine API if you want to embed the framework within another application.
You need to use the MS App id and password for all channels apart from the Emulator. If you use DirectLine API, you will also have to pass a secret token.

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).

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.

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

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!

Sending messages to my bot via Slack gets no response

I have a bot deployed to our Azure subscription. Using the webchat channel, I can interact with the bot using the url:
http://mybotname.azurewebsites.net/
We have added the bot to Slack as an app. We followed all the instructions given by the documentation on how to add a bot into Slack - https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-slack?view=azure-bot-service-3.0
When I send a message to the bot in the Slack channel we have created, I get no response. There is not error message, or in fact anything, returned.
Whereabouts can I start looking to see what the problem could be? Suggestions for error logs, traces, etc would be appreciated. I enabled App insights for the Azure Web App which the bot runs under, but nothing comes up as an error, or warning, or anything. I'm a bit lost here, any suggestions would be appreciated.
Note that I was made aware that, for Slack, I may need to tailor the responses in order for Slack to render them e.g. FormFlow define options for string field
I'm not sure how to do that, or even if this is a case that my bot simply isn't working in Slack regardless of how I'd format the responses.

creating a slack bot using slack-api ruby gem not responding back as a DM

I have set up a slack bot using slack-api and the real-time-messaging api.
Here is the abbreviated setup:
client.on :message do |data|
d {data}
bot_response = BotResponse.get_bot_response(data['text'], "session_slack")
Slack.chat_postMessage channel: data['user'], text: "#{bot_response}"
end
client.start
With this version of the postMessage, the response comes from Slackbot, not my bot (named kaya).
Goal: I want to respond to come as a DM from the bot it was sent to.
When I change the channel to data['channel'], the response comes as DM from my bot kaya, but gets into an endless loop.
How do I have a non-endless loop DM response?
NOTE:
I think I see how it is happening: by selecting the bot as the "channel" the bot is responding to it's own response back to me, as if it were another user talking into the "bot's" channel. But I can't tell how else to have the response come from my bot, not slackbot.
I believe you need to include the username parameter set to the bot name per the api: https://api.slack.com/methods/chat.postMessage, or you need the as_user option.
This mixes the Web and the RealTime Messaging API. You get a message from the RealTime Messaging API then you are using the Web API to post back. The answer of including as_user: true is correct, but you should instead use the RTM API to send the message back.
Try https://github.com/dblock/slack-ruby-client instead that cleanly separates the two. Sending a message back as the bot looks like this:
client.message channel: data['channel'], text: "Hi <##{data['user']}>!"
To avoid DM loops, make sure you're not responding to commands that you emit. There're other ways, like ignoring bot messages, but it's not as reliable.

Resources