bot framework not receiving Slack dialog.open form response - botframework

I am building bot with Bot Builder SDK for Node.js
The bot is for slack
I have configured the slack and botframework correctly, as per the doc Connect a bot to Slack
All communication between botframework, slack and node service is through HTTPS.
The framework is communicating with slack properly.
In Next step, I am working on slack dialog.open
First of all, I could not find any method in Bot Builder SDK, to open the slack dialog, I even tried to Implement channel-specific functionality
Finally I was able to open dialog with direct post to: https://slack.com/api/dialog.open
But when I submit the form, I am getting error:
We had some trouble connecting. Try again?
Please see the screenshot:
The console displays the following error:
Request URL: https://xxxxx.slack.com/api/dialog.submit
Response: {"ok":false,"error":"curl_error"}
Slack send payload with "type":"dialog_submission".
I have tested that by changing the "Interactive Components -> Request URL", to my bot service.
To make slack communicate directly to my bot service.
Reference: section "Add and Configure Interactive Messages (optional)" in Connect a bot to Slack
So, I am sure message is being sent from the dialog box, when I click on submit button.
The message is lost between slack and my bot service. when Request URL is set to: https://slack.botframework.com/api/Actions
I never receives any indication that service is receiving a message.
Please help me to resolve this problem.
Following is the code that I used to open the dialog:
let RESTClient = require('node-rest-client').Client;
let FrameworkClient = new RESTClient();
let Promise = require('bluebird');
openDialogBox: function(token, trigger_id, callback_id) {
return new Promise(function(resolve, reject) {
var dialog = {
"title": "Issue Details",
"submit_label": "Submit",
"callback_id": callback_id,
"elements": [
{
"type": "text",
"label": "Pickup Location",
"name": "loc_origin"
},
{
"type": "text",
"label": "Dropoff Location",
"name": "loc_destination"
}
]
};
var args = {};
args.headers = {Authorization: 'Bearer ' + token, 'Content-type': 'application/json; charset=utf-8'};
args.data = {"trigger_id": trigger_id, "dialog": dialog};
FrameworkClient.post("https://slack.com/api/dialog.open", args , function(data, response) {
if (data && data.ok) {
resolve(data);
} else {
reject();
}
});
});
}
Thanks

As per #JasonSowers (Engineer - Microsoft Bot Framework)
Microsoft Bot Framework do not support this right now.
They may support this in future.

Related

OnMembersAddedAsync is not getting called

I have Bot developed in .NET core 3.1 c#. I am sending Adaptive card in OnMembersAddedAsync. It ix expected that as soon as end customer open chat control it should send Adaptive card. This is working well in Azure web chat control & emulator. But when I added it web site and open chat control in web site it will not work. Control will wait for end customer to send some message & then it sends card. In console log of BotFrame.html I can see that DIRECT_LINE connection is established :
DIRECT_LINE/CONNECT_PENDING
DIRECT_LINE/UPDATE_CONNECTION_STATUS
DIRECT_LINE/UPDATE_CONNECTION_STATUS
DIRECT_LINE/CONNECT_FULFILLING
DIRECT_LINE/CONNECT_FULFILLED
My code for BotFrame.html is :
const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
console.log(action.type);
if ( action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' ) {…..
}
}
Even in Bot Logs I cannot see OnMembersAddedAsync is called unless customer sends message. Am I missing anything. Same is working well in Azure web chat control & emulator.
This sample, 04.api/a.welcome-event, demonstrates best practice on how to setup Web Chat and your bot for sending a welcome message.
In short, as shown in the sample, you will send an event to your bot when direct line connects your bot and the client.
When the event is received by the bot, it will trigger the bot to send the actual welcome message/card/activity to the user via the client.
In Web Chat
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
In Your Bot
if (context.activity.name === 'webchat/join') {
await context.sendActivity('Welcome, friend!!');
}
Hope of help!

How to send pro-active message to all teams users using botbuilder v4 nodejs

I am able to send the pro-active messages using v3
const address =
{
channelId: 'msteams',
user: { id: '29:1smZ9yn-ggTRUgd2ytQzb7PeTwmMBJs-WVlm3sXGwgjklvxycg' },
channelData: {
tenant: {
id: ''
}
},
bot:
{
id: '',
name: ''
},
serviceUrl: 'https://smba.trafficmanager.net/in/',
useAuth: true
}
var msg = new builder.Message().address(address);
msg.text('Hello, this is a notification');
bot.send(msg);
But I want to send the pro-active messages using v4.I have a accessToken which I got from Oauth 2.0 (code-grant). In the docs everywhere it is mentioned to save the turnContext.activity when user messages bot and use it for future reference. But I want to send message to user even before he messages the bot. What I am trying to do is install bot to users teams (like slack apps) using oauth and ask questions to users.

Trouble writing a proactive message Microsoft Teams Bot

I'm currently trying to send a proactive message with my Microsoft Teams bot by using the following example code that I see online:
var address =
{
channelId: 'msteams',
user: { id: userId },
channelData: {
tenant: {
id: tenantId
}
},
bot:
{
id: appId,
name: appName
},
serviceUrl: session.message.address.serviceUrl,
useAuth: true
}
var msg = new builder.Message().address(address);
msg.text('Hello, this is a notification');
bot.send(msg);
The only change made is that I use TeamsMessage instead of a regular Message because I get errors saying that Message isn't a class which has also confused me. The problem when I run the code is that it tells me that my bot doesn't have a function named 'send'. My bot extends the TeamsActivityHandler class. My question is how do I fix this issue?
You need the user’s unique ID and tenant ID to send a proactive message. Typically, these are obtained from a team context, either by fetching the team roster or when a user interacts with your bot in a channel. Please check documentation on how to send proactive message.
Here is the source code for Node.js sample for Proactive Messages.

Read Custom request Header in OWIN Authentication

I am trying to provide extra/custom authentication to MS Bot-framework project using OWIN other than default authentication from MS using app id/pwd. Yes the Bot is in-fact an api i tagged Webapi too. I added OWIN startup class and provided middleware to perform OAUTH-2 implementation to validate JWT.
As MS Bot directline calls have a default Bearer token to be passed as Authorization header key,i given custom provider to accept JWT from Bot state. Please note my bot is surfaced in a Web app which will generate a auth token which will be setted in Bot state against unique user id, so i am in need of this user id value to retrieve the token from Bot state. So the best possible way i can think of is to intercept all ajax calls from my Webchat Bot control to add a custom header as "x-user-id", which i will read from my owin middleware request header.
But it was not succeeding as i am not getting the header value in OWIN, which i am passing in ajax calls. But when i checked in Chrome, this header is being sent. I am confused on what could be the issue.
Ajax Interceptor
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
(function (send) {
XMLHttpRequest.prototype.send = function (data) {
this.setRequestHeader('x-user-id', '123456789');
send.call(this, data);
};
})(XMLHttpRequest.prototype.send);
}
AppBuilder Configuration
public void Configuration(IAppBuilder app)
{
var policy = new CorsPolicy()
{
AllowAnyHeader = true,
AllowAnyMethod = true,
AllowAnyOrigin = true,
SupportsCredentials = true
};
policy.ExposedHeaders.Add("x-user-id");
app.UseCors(new CorsOptions()
{
PolicyProvider = new CorsPolicyProvider
{
PolicyResolver = context => Task.FromResult(policy)
}
});
app.Map("/api", ctx =>
{
ctx.UseEsoAccessTokenValidation(new EsoAccessTokenOptions
{
AccessTokenKey = "AccessToken",
ChannelId = "webchat",
Scopes = new string[] { "read", "write" }
});
ctx.UseWebApi(WebApiConfig.Register());
});
}
Code to Read Header:
private static async Task<string> GetAccessToken(OAuthRequestTokenContext context, EsoAccessTokenOptions options)
{
string accesstoken = string.Empty;
var request = context.Request;
if (request.Headers.ContainsKey("x-user-id"))
{
userid = request.Headers.Get("x-user-id");
}
}
Chrome Network Screenshot
Please help me understand what i am doing wrong here?
Need to realize that, the requests always pass through the corresponding channels (connectors) and not everything that you add as part of headers will be passed to your bot. Hence we need to pass such data only through supported mechanisms. as Eric mentioned, once such way is leveraging channelData. Anything that you add as part of channelData will pass thru the channel and reach the bot. Hence recommend you to try the same.
Example 1:
{
"type": "conversationUpdate",
"membersAdded": [],
"from": {
"id": "test",
"name": "test"
},
"serviceUrl": "https://directline.botframework.com",
"channelData":{ "userId": "test"}
}
Example 2:
{
"type": "message",
"text": "whats your name",
"from": {
"id": "user1",
"name": "user1"
},
"channelData": {
"userId": "test1234"
}
}`
Hope this helps.
I think the Direct Line strips headers as it translates and transfers messages to your bot. However, you could intercept all messages (like you've done already) and add the x-user-id as custom channel data to each message. Here is an example of custom channel data: https://blog.botframework.com/2017/03/28/Custom-Channel-Data#c-implementation

slack api rtm direct message

I'm using a node package: slack-client to interact with the api at slack. Now with or without using slack-client how do I send a direct message from my bot to a user I want to specify? Here's what have so far with a plain socket connection:
var WebSocket = require('ws')
,ws2 = new WebSocket(myURL); //from rtm start
ws2.on('open', function() {
ws2.send({
"id": 333,
"type": "message",
"channel": "#user1", //User I want to send to
"text": "HEY!!!!"
});
});
ws2.on('message', function(message) {
console.log('received: %s', message);
});
I was hoping that message would go directly to me from the bot but nothing. I get a reply of type hello though? The send details above I got on another post about this but it doesn't work for me. The message Id was one I created.
Ok so when calling the rtm.start via the web api, you would get a list of DM's that would be open for various users otherwise you can easily just open an im with im.open. I'm using the node package slack-client as mentioned in my question so you can do this:
//name of user your bot wants to send a msg to.
var userTest = slack.getUserByName('user1');
slack.openDM(userTest.id, function(res)
{
TestMsg(res.channel.id, 'some other msg');//test function I'm using
});
Next is the TestMsg function:
function TestMsg(userChannelId, msg)
{
request.post({url: 'https://slack.com/api/chat.postMessage',
form: { token: "xxxx-yourbot-token",channel: userChannelId,text: msg ,username: "yourBotNamehere", as_user: false}
}, function(error, response, body){
console.log(response.body);
});
}
I couldn't get it to work yet using the websockets send method but I suppose the api of postMessage will do for now as you can post richly formatted messages with postMessage. Hope this helps someone

Resources