我有一个通过登录进行身份验证的客户端,我需要在每个请求中将该userId和token传递给bot,以便我可以使用它来命中我需要此信息的服务器Web api。我尝试获取标题中的授权,但它带有秘密。如果我可以将标识和标记附加到标题,它对我有用。
this.botConnection = new BotChat.DirectLine({
secret: 'yNy9g1Mok1g.cwA.fyks.fghsth.rcKOQUIu558-TI',//params['mysecret'],
token: params[this.token], //I think I should pass it here but this does not work.
//domain: params['ngroktunneledurl.com/api/messages'],
webSocket: params['webSocket'] && params['webSocket'] === "true" // defaults to true,
});
然后从机器人试图在消息控制器中检索令牌..
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
var keyValuePair = Request.Headers.FirstOrDefault(h => h.Key.Equals("Authorization"));
token = keyValuePair.Value.First().Substring(7);
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog(token));
}
else
{
HandleSystemMessage(activity).ConfigureAwait(false);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
授权带来了识别我们机器人的秘密。
答案 0 :(得分:0)
ChannelData 不会被连接器服务剥离。虽然此属性旨在提供特定于通道的功能,但它也可用于将额外信息从bot客户端传递到bot:https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-channeldata
答案 1 :(得分:0)
你可以将你的令牌或任何类型的字符串的值传递给id并用标识符将其连接起来,这样你就可以拆分内部代码并将其作为一个数组。
使用以下代码:
<div id="bot"></div>
<script>
var spCOntext;
var FirstName;
var emailaddress;
var Environment;
try{
spCOntext = "your context";
FirstName = _spPageContextInfo.userDisplayName;
emailaddress = "your email";
Environment= "application URL";
}
catch(ex)
{
spCOntext = 'You';
Environment = 'Local System';
}
BotChat.App({
directLine: { secret: 'Your secret' },
//directLine: { secret: 'Your secret' },
user: { id: FirstName ,Name: spCOntext+'*'+Environment},
bot: { id: 'your bot id' },
resize: 'detect'
}, document.getElementById("bot"));
</script>
你可以在你的bot c#代码中得到这样的值:
public async Task AltairQueryResponse(IDialogContext context, IAwaitable<IMessageActivity> response)
{
var message = await response;
var getContext = message.From.Name.Split('*')[0];// get context
var Environment= message.From.Name.Split('*')[0];// get Environment
await context.PostAsync(getContext);
await context.PostAsync(Environment);
}
如果您需要任何其他帮助,请告诉我