简体   繁体   English

[BotFramework]:在使用C#SDK V4开发的BOT中,是否可以在英雄卡或自适应卡中显示Oauth提示?

[英][BotFramework]: Is there a way to Display Oauth prompt in hero card or Adaptive card in a BOT Developed using SDK V4 in C#?

在此处输入图片说明 I am developing a chatbot using V4 in C#; 我正在使用C#中的V4开发聊天机器人; I have implemented an authentication functionality inside a waterfall dialog using OauthCard prompt, I want this oauth card prompt to be displayed inside a Hero Card or Adaptive card or any other card that is suitable such that Login functionality works in Webchat Channel. 我已经使用OauthCard提示在瀑布对话框中实现了身份验证功能,我希望此oauth卡提示显示在Hero卡或Adaptive卡或任何其他合适的登录卡中,以便登录功能可在Webchat Channel中使用。

Currently, the oauth card prompt is not displayed in the webchat Channel as a result I am unable to login so thought if I can display the sign in functionality of oauth Prompt in Hero card or any suitable card then I can proceed it with authentication functionality. 目前,由于无法登录,因此无法在网络聊天频道中显示oauth卡提示,因此,如果可以在Hero卡或任何合适的卡中显示oauth Prompt的登录功能,则可以进行身份​​验证功能。

I have enabled Oauth Prompt using the below link and it perfectly works fine in emulator: 我使用下面的链接启用了Oauth Prompt,它在模拟器中可以正常运行:

How to fix next step navigation with oauth prompt in waterfall dialog in SDK V4 bot created using C# without typing anything? 如何在不键入任何内容的情况下使用C#创建的SDK V4机器人的瀑布对话框中的oauth提示符下修复带有oauth提示的下一步导航?

But not able to do it in Webchat Channel hence thought if i keep this in hero card it can work. 但是无法在Webchat频道中执行此操作,因此认为如果将其保存在英雄卡中,它将可以正常工作。

  • Language: C# 语言:C#
  • SDK: V4 SDK:V4
  • Channel: WebChat channel 频道:WebChat频道

Please provide the code or procedure in step by step in a detailed guide manner as I am fairly new to BOT and coding so that i can fix my issue. 由于我对BOT和编码还很陌生,因此请以详细的指导方式逐步提供代码或过程,以便我解决问题。

Please help. 请帮忙。

Thanks & Regards -ChaitayaNG 致谢-ChaitayaNG

I do not know how to do it so i tried do the following in index.html: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/18.customization-open-url 我不知道该怎么做,所以我尝试在index.html中执行以下操作: https : //github.com/microsoft/BotFramework-WebChat/tree/master/samples/18.customization-open-url

This is did not work for me either. 这对我也不起作用。

I looked into the below links also but according to my understanding there was comments for Team Channel but nothing concrete for webchat channel: 我也查看了以下链接,但据我了解,对团队频道有评论,但对于网络聊天频道没有具体评论:

https://github.com/microsoft/botframework-sdk/issues/4768 https://github.com/microsoft/botframework-sdk/issues/4768

I also looked into belowlink but since it was related to React i did not investigate it as i am doing the chatbot in webchat channel and in azure C#: 我也查看了以下链接,但是由于它与React有关,因此我没有进行调查,因为我正在Webchat频道和Azure C#中使用chatbot:

https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/10.a.customization-card-components https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/10.a.customization-card-components

I also tried to call oauth prompt inside Singin card which did not work as it was not invoking the prompt either in Emulator or Webchannel. 我还尝试在Singin卡中调用oauth提示,该提示不起作用,因为它没有在Emulator或Webchannel中调用提示。

Hence i need help as the oauth cards are not loading in Web Chat channel even after following above links information. 因此,我需要帮助,因为即使遵循上述链接信息,oauth卡也不会加载到Web聊天频道中。 So thought if we can keep in some cards it can be done but did not find any thing concrete to do also. 因此,以为如果我们可以保留一些卡片,可以做到,但没有发现任何具体的事情也可以做。 Since i am new to BOT and coding i may have missed something so please help or provide step by step guide on how t do it. 由于我是BOT和编码的新手,所以我可能错过了一些东西,所以请帮助或提供逐步指导。

Expected Result: Need the oauth prompt to be displayed inside a HeroCard or any other suitable card as it is code is not working or loading the oauth prompt in Webchat channel working fine in Emulator. 预期结果:需要将oauth提示显示在HeroCard或任何其他合适的卡中,因为代码不起作用,或者在Webchat通道中加载oauth提示在Emulator中工作正常。 Actual Result: Do not know how to achieve it. 实际结果:不知道如何实现。

Adding details as per the comments from Richardson: Hi Richardson, 根据Richardson的评论添加详细信息:您好Richardson,

I have used OauthPrompt in a Water fall dialog where in STEP 1: I display OAuthCard prompt where i click on link and it pops up a new window to enter credentials and it gives a magic code. 我在瀑布对话框中使用了OauthPrompt,在第1步中:我显示OAuthCard提示符,然后单击链接,它会弹出一个新窗口以输入凭据,并提供了一个神奇的代码。 I enter the magic code in browser it goes to STEP 2: Here i am retrieving token and proceeding further as i said this is working in Emulator as described in below link: 我在浏览器中输入魔术代码,然后转到步骤2:在这里,我正在检索令牌,并进一步进行操作,因为我说这将在仿真器中工作,如下面的链接所述:

How to fix next step navigation with oauth prompt in waterfall dialog in SDK V4 bot created using C# without typing anything? 如何在不键入任何内容的情况下使用C#创建的SDK V4机器人的瀑布对话框中的oauth提示符下修复带有oauth提示的下一步导航?

Coming to Webchat it displayed me the following: [File of type 'application/vnd.microsoft.card.oauth'] 来到Webchat时,向我显示了以下内容:[文件类型'application / vnd.microsoft.card.oauth']

Instead of sign in button or link. 而不是登录按钮或链接。

The code i used is the following: 我使用的代码如下:

public class LoginDialog : WaterfallDialog
{
    public LoginDialog(string dialogId, IEnumerable<WaterfallStep> steps = null)
         : base(dialogId, steps)
    {
        AddStep(async (stepContext, cancellationToken) =>
        {
            await stepContext.Context.SendActivityAsync("Please login using below option in order to continue with other options...");

            return await stepContext.BeginDialogAsync("loginprompt", cancellationToken: cancellationToken); // This actually calls the  dialogue of OAuthPrompt whose name is  in EchoWithCounterBot.LoginPromptName.  


        });

        AddStep(async (stepContext, cancellationToken) =>
        {
            Tokenresponse = (TokenResponse)stepContext.Result;

            if (Tokenresponse != null)
            {

                await stepContext.Context.SendActivityAsync($"logged in successfully... ");


                return await stepContext.BeginDialogAsync(DisplayOptionsDialog.Id); //Here it goes To another dialogue class where options are displayed
            }
            else
            {
                await stepContext.Context.SendActivityAsync("Login was not successful, Please try again...", cancellationToken: cancellationToken);


                await stepContext.BeginDialogAsync("loginprompt", cancellationToken: cancellationToken);
            }

            return await stepContext.EndDialogAsync();
        });
    }

    public static new string Id => "LoginDialog";

    public static LoginDialog Instance { get; } = new LoginDialog(Id);
}

In the maindialog called as Mainrootdialog class: 1. I have a variable LoginPromptName = "loginprompt" and another parameter for connection name; 在称为Mainrootdialog类的maindialog中:1.我有一个变量LoginPromptName = "loginprompt"和另一个用于连接名称的参数; public const string ConnectionName = "conname";

  1. Then I have a method called prompt which accepts connection name and has oauthprompt related code as given below: 然后,我有一个名为提示符的方法,该方法接受连接名称,并具有如下所示的与oauthprompt相关的代码:
  private static OAuthPrompt Prompt(string connectionName)
        {
            return new OAuthPrompt(
               "loginprompt",
               new OAuthPromptSettings
               {
                   ConnectionName = connectionName,
                   Text = "signin",
                   Title = "signin",
                   Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 
               });
        }
  1. Finally this prompt is added in the Dialogset or stack as below: 最后,此提示将添加到对话框集或堆栈中,如下所示:
     public MainRootDialog(UserState userState)
            : base("root")
        {
            _userStateAccessor = userState.CreateProperty<JObject>("result");

            AddDialog(Prompt(ConnectionName));
            AddDialog(LoginDialog.Instance);            
            InitialDialogId = LoginDialog.Id;
        }

As tried to explain earlier works perfectly fine in emulator as you could see from my comments in the above shared link 正如您试图在模拟器中完美解释的那样,您可以从上面共享链接中的评论中看到

But in webchat channel does not load button or link gives me this: [File of type 'application/vnd.microsoft.card.oauth'] 但是在网络聊天频道中不会加载按钮或链接,这给了我:[类型为'application / vnd.microsoft.card.oauth'的文件]

I tried the following GitHub link which i did not work pasting or attaching the HTML file for reference: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/18.customization-open-url 我尝试了以下GitHub链接,但我无法粘贴或附加HTML文件以供参考: https : //github.com/microsoft/BotFramework-WebChat/tree/master/samples/18.customization-open-url

 <!DOCTYPE html> <html lang="en-US"> <head> <title>Web Chat: Customize open URL behavior</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js", or lock down on a specific version with the following format: "/4.1.0/webchat.js". --> <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script> <style> html, body { height: 100% } body { margin: 0 } #webchat, #webchat > * { height: 100%; width: 100%; } </style> </head> <body> <div id="webchat" role="main"> <iframe src='https://webchat.botframework.com/embed/TestBotForOauthPrompt?s=<<Given my secretkey of web chat channel>>' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe> </div> <script> (async function () { // In this demo, we are using Direct Line token from MockBot. // To talk to your bot, you should use the token exchanged using your Direct Line secret. // You should never put the Direct Line secret in the browser or client app. // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication const res = await fetch('https://testbotforoauthprompt.azurewebsites.net//directline//token', { method: 'POST' }); const { token } = await res.json(); window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token }), // We are adding a new middleware to handle card action cardActionMiddleware: () => next => async ({ cardAction, getSignInUrl }) => { const { type, value } = cardAction; switch (type) { case 'signin': // For OAuth or sign-in popups, we will open the auth dialog directly. const popup = window.open(); const url = await getSignInUrl(); popup.location.href = url; break; case 'openUrl': if (confirm(`Do you want to open this URL?\\n\\n${ value }`)) { window.open(value, '_blank'); } break; default: return next({ cardAction, getSignInUrl }); } } }, document.getElementById('webchat')); document.querySelector('#webchat > *').focus(); })().catch(err => console.error(err)); </script> </body> </html> 

Coming to the link you have provided it does not open it gives me 404 error 来到您提供的链接无法打开它给我404错误


Date: 29-May-2019 Reason: Further queries on inputs provided by Richardson 日期:2019年5月29日原因:进一步询问Richardson提供的意见

I understand there is a .NET Code written inside a controller class which generates the Token. 我了解在生成令牌的控制器类中编写了.NET代码。 There is a html page to load our web chat which contains required scripts to store or expose tokens and then the chat bot opens whenever we open this HTML file. 有一个用于加载网络聊天的html页面,其中包含存储或公开令牌所需的脚本,然后只要打开此HTML文件,聊天机器人就会打开。 However, I have following queries. 但是,我有以下查询。 These might seem very basic but please bear with me as I am new to coding: 这些看起来很基础,但是请耐心接受,因为我是编码新手:

  1. Where the code should be written, how will it get called because I am not specifying in my html script or anywhere call the Controller class Index method to generate the token and use it? 应该在哪里编写代码,如何调用该代码,因为我未在html脚本中指定或在任何地方调用Controller类Index方法来生成令牌并使用它? Or will it call automatically the index method inside controller. 或者它将自动调用控制器内部的index方法。 If not, automatically where should I specify this that u call index method? 如果没有,我应该在哪里自动指定u调用索引方法? Is it possible to provide whole solution like having bot code and controller class at solution so that I can get a better picture so that I can ask any other further queries if any? 是否可以提供完整的解决方案,例如在解决方案中包含机器人代码和控制器类,这样我可以得到更好的画面,以便可以询问其他任何进一步的查询(如果有)?

  2. Is this .net code is a separate solution or inside the same bot solution controller class should be written? .net代码是单独的解决方案还是应该在同一机器人解决方案控制器类中编写? If separate solution, then how to publish this to the BOT resource in azure? 如果是单独的解决方案,那么如何将其以蓝色发布到BOT资源? How bot and new solution will interact automatically without providing any connection? 僵尸程序和新解决方案如何在不提供任何连接的情况下自动交互?

  3. I am assuming it should a new class inside the same BOT Code solution in Visual Studio. 我假设它应该在Visual Studio的同一BOT代码解决方案内创建一个新类。 Now, I have further queries on this(based on this assumption): 现在,我对此有进一步的查询(基于此假设):

a. 一种。 As per my understanding on your explanation the post method is not working because there is no Token generator, so it gives you an error. 根据我对您的解释的理解,post方法不起作用,因为没有令牌生成器,因此它会给您一个错误。 You can use the below link to write the code and get the token which again brings to question number 1? 您可以使用下面的链接编写代码并获取令牌,该令牌又使问题1出现?

What is the correct way to authenticate from JavaScript in an HTML file to the Microsoft Web Chat control for Bot Framework v4? 从HTML文件中的JavaScript到Bot Framework v4的Microsoft Web Chat控件进行身份验证的正确方法是什么?

b. b。 In the HTML file if I write the script given as per above link then should be in the same async function or we have to remove the async function? 在HTML文件中,如果我编写了按上述链接给出的脚本,则该脚本应位于相同的异步函数中,否则我们必须删除异步函数?

c. C。 Still the style options like BOT Avatar and etc work if kept as is ? 如果保持原样,像BOT Avatar之类的样式选项是否仍然有效? same way other scripts for displaying welcome message? 其他脚本显示欢迎消息的方式是否相同?

d. d。 In the GetElementByID('') we are passing bot as the value from the link above but in actual samples we pass web chat is it because we have changed the POST method to the new script? 在GetElementByID('')中,我们通过上面的链接传递bot作为值,但在实际示例中,我们传递了网络聊天,这是因为我们已经将POST方法更改为新脚本了吗?

e. e。 Should the post method still be kept or can be removed? 应该保留张贴方法还是可以将其删除? Instead of the post line: 代替发布行:

const res = await fetch(' https://examplebot.azurewebsites.net/directline/token ', { method: 'POST' }); const res = await fetch(' https://examplebot.azurewebsites.net/directline/token ',{method:'POST'}); Write new one as below: the script given below (taken from above link): 编写如下新脚本:下面给出的脚本(摘自上面的链接):

@model ChatConfig
@{
    ViewData["Title"] = "Home Page";
}
<link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
<div id="bot" />
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<script>
      BotChat.App({
          directLine: {
              secret: '@Model.Token'
          },
        user: { id: @Model.UserId },
        bot: { id: 'botid' },
        resize: 'detect'
      }, document.getElementById("bot"));
</script>
  1. You have also explained that to avoid all these complications and make it simple just keep your secret in the file: Current: const { token } = await res.json(); 您还解释了为避免所有这些复杂情况并使它变得简单,只需将您的秘密保存在文件中即可:Current:const {token} = await res.json(); To make it simple: const { token } = <>; 简单起见:const {token} = <>; Is my understanding, right? 我的理解对吗?

  2. On top of 4th question: Then the POST method line should also be removed ie below line and we don't have to write the new controller class or the script given above of Model config and rest keep as is: Something like below and the bot loads when I open the page and the OAuth prompts and adaptive cards work without any issue: 在第四个问题之上:然后,也应该删除POST方法行,即在该行下面,我们不必编写新的控制器类或上面的Model config脚本,其余的保持原样:类似于下面和bot当我打开页面并加载OAuth提示和自适应卡片时,加载不会出现任何问题:

    Avanade D365 F&O Assets BOT Avanade D365 F&O资产BOT

     <!-- For demonstration purposes, we are using development branch of Web Chat at "/master/webchat.js". When you are using Web Chat for production, you should use the latest stable at "/latest/webchat.js". Or locked down on a specific version "/4.1.0/webchat.js". --> <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script> <style> html, body { height: 100% } body { margin: 0 } #webchat { height: 100%; width: 100%; } </style> 

     </div> <script> (async function () { // In this demo, we are using Direct Line token from MockBot. // To talk to your bot, you should use the token exchanged using your Direct Line secret. // You should never put the Direct Line secret in the browser or client app. // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication const { token } = <<Directline secret from azure portal durect line channel>>; const styleOptions = { botAvatarImage: 'https://docs.microsoft.com/en-us/azure/bot-service/v4sdk/media/logo_bot.svg?view=azure-bot-service-4.0', botAvatarInitials: 'BF', userAvatarImage: 'https://avatars1.githubusercontent.com/u/45868722?s=96&v=4', userAvatarInitials: 'WC', bubbleBackground: 'rgba(0, 0, 255, .1)', bubbleFromUserBackground: 'rgba(0, 255, 0, .1)' }; // We are using a customized store to add hooks to connect event 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 } } }); } return next(action); }); window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token }), store }, document.getElementById('webchat')); document.querySelector('#webchat > *').focus(); })().catch(err => console.error(err)); </script> 

Is my understanding, right? 我的理解对吗?


30 May 2019 ChaitanyaNG Updates for the Comment: Screenshot: For reference on the findings of using the HTML file provided by Richardson as is and replacing it by my BOT Direct Channel secret key 2019年5月30日更新ChaitanyaNG的评论:屏幕快照:供参考使用Richardson提供的HTML文件原样并将其替换为我的BOT Direct Channel密钥

The real issue is in your comment here: 真正的问题在您的评论中:

Coming to Webchat it displayed me the following: [File of type 'application/vnd.microsoft.card.oauth'] 来到Webchat时,向我显示了以下内容:[文件类型'application / vnd.microsoft.card.oauth']

which is caused by: 原因是:

<div id="webchat" role="main">
        <iframe src='https://webchat.botframework.com/embed/TestBotForOauthPrompt?s=<<Given my secretkey of web chat channel>>' style='min-width: 400px; width: 100%; min-height: 500px;'></iframe>
    </div>
    <script>
      (async function () {
        // In this demo, we are using Direct Line token from MockBot.
        // To talk to your bot, you should use the token exchanged using your Direct Line secret.
        // You should never put the Direct Line secret in the browser or client app.
        // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication
        const res = await fetch('https://testbotforoauthprompt.azurewebsites.net//directline//token', { method: 'POST' });
        const { token } = await res.json();

First issue: You're using both the iframe ( <iframe src='https://webchat... ) and WebChat ( <script> (async function ()... ). 第一个问题:您同时使用iframe( <iframe src='https://webchat... WebChat( <script> (async function ()... )。

Fix: Remove the iframe and just use the WebChat code . 修复:删除iframe并仅使用WebChat代码 This isn't really documented anywhere, but the iFrame uses botchat , which is an older version of WebChat, which doesn't work with OAuth and is what's giving you the [File of type... error. 这在任何地方都没有实际记载,但是iFrame使用的是botchat ,它是WebChat的较旧版本,无法与OAuth配合使用,并且为您提供了[File of type...错误。

Second issue: You aren't getting a valid token 第二个问题:您没有获得有效的令牌

const res = await fetch(' https://testbotforoauthprompt.azurewebsites.net//directline//token ', { method: 'POST' }); const res =等待fetch(' https://testbotforoauthprompt.azurewebsites.net//directline//token ',{method:'POST'});

That code returns a 404 because https://testbotforoauthprompt.azurewebsites.net/directline/token doesn't exist. 该代码返回404,因为https://testbotforoauthprompt.azurewebsites.net/directline/token不存在。

You should follow the guide linked in the code comments , which would have you make a POST request to https://directline.botframework.com/v3/directline/tokens/generate with Authorization: Bearer <YourSecretFromAzurePortal> in the header. 您应该遵循代码注释中链接的指南,该指南将使您向POST请求发送https://directline.botframework.com/v3/directline/tokens/generate ,并在标题中添加Authorization: Bearer <YourSecretFromAzurePortal>

Alternatively, you can use const token = <YourSecretFromAzurePortal> directly, instead. 另外,您可以直接使用const token = <YourSecretFromAzurePortal> Note that it isn't a good idea to use your secret directly. 请注意,直接使用您的秘密不是一个好主意。 You should really set up a token server. 您应该真正设置一个令牌服务器。 This should get you started (note: this is the link I intended to use in my comment above), but it's a little more complex. 这应该可以帮助您入门 (注意:这是我打算在上面的评论中使用的链接),但是稍微复杂一些。 If you just want something simple and don't care if your app secret gets out, go with the const token = <YourSecretFromAzurePortal> method. 如果您只是想要简单的东西,而不管您的应用程序密码是否泄露,请使用const token = <YourSecretFromAzurePortal>方法。

I just answered a similar question, here. 我刚刚在这里回答了类似的问题。


Regarding your updates 关于您的更新

Token Generator 代币生成器

Regarding: this answer 关于: 这个答案

If you want to keep your Secret private, you need to write your own token server. 如果您想将Secret保密,则需要编写自己的令牌服务器。 The first half of the linked answer explains a basic way to do this. 链接答案的前半部分说明了执行此操作的基本方法。 You can either write your own, use the sample in that linked answer, or use the code from the blog posts that are linked in that answer. 您既可以编写自己的代码,也可以在链接的答案中使用示例,也可以使用在该答案中链接的博客文章中的代码。

Where to put the code is dependent on how you want it to run. 将代码放在何处取决于您希望它如何运行。 The sample token server is entirely separate from the bot. 样本令牌服务器与机器人完全分开。 The blog post samples show how to integrate it into your bot (although you can also host it separately). 博客文章样本展示了如何将其集成到您的机器人中(尽管您也可以单独托管它)。

The WebChat client makes a request to that token server, which makes a request to https://directline.botframework.com/v3/directline/tokens/generate and returns the response, which is a valid DirectLine token. WebChat客户端向该令牌服务器发出请求,该令牌服务器向https://directline.botframework.com/v3/directline/tokens/generate发出请求并返回响应,这是有效的DirectLine令牌。

However, in many cases you don't need the extra security of writing your own token server. 然而,在许多情况下,你不需要编写自己的令牌服务器的额外的安全性。 The second half of the linked answer explains that the security risks of exposing your secret are minimal for many simple bots. 链接答案的后半部分说明,对于许多简单的漫游器而言,暴露秘密的安全风险很小。

I recommend, for you (since you said you're fairly new to coding), that you don't write your own token server and just leave the secret exposed in const token = <Directline secret from azure portal direct line channel>; 我建议您(因为您说过对编码还不const token = <Directline secret from azure portal direct line channel>; ),所以不要编写自己的令牌服务器,而const token = <Directline secret from azure portal direct line channel>;公开在const token = <Directline secret from azure portal direct line channel>; (Note that I removed the {} , since your token is a string ). (请注意,我删除了{} ,因为您的令牌是一个string )。 If you really want to use a token server, you'll need to learn how to write a server in C#. 如果您真的想使用令牌服务器,则需要学习如何用C#编写服务器。

HTML File HTML文件

The code you got from examplebot.azurewebsites... uses Angular (I think). 您从examplebot.azurewebsites...获得的代码使用Angular(我认为)。 It's old. 老了 Don't use it. 不要使用它。

You should base your HTML code off of one of the WebChat Samples . 您应该基于WebChat示例之一创建HTML代码。

It looks like your last code block does. 看起来就像您的最后一个代码块一样。 Since there's been a lot of confusion, just use this: 由于存在很多混乱,请使用以下命令:

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat: Custom style options</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--
      For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
      When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
      or lock down on a specific version with the following format: "/4.1.0/webchat.js".
    -->
    <script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
    <style>
        html, body {
            height: 100%
        }

        body {
            margin: 0
        }

        #webchat {
            height: 100%;
            width: 100%;
        }
    </style>
  </head>
  <body>
    <div id="webchat" role="main"></div>
    <script>
      (async function () {
        // In this demo, we are using Direct Line token from MockBot.
        // To talk to your bot, you should use the token exchanged using your Direct Line secret.
        // You should never put the Direct Line secret in the browser or client app.
        // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication

        // Token is found by going to Azure Portal > Your Web App Bot > Channels > Web Chat - Edit > Secret Keys - Show
        // It looks something like this: pD*********xI.8ZbgTHof3GL_nM5***********aggt5qLOBrigZ8
        const token = '<Directline secret from azure portal durect line channel>';

        // You can modify the style set by providing a limited set of style options
        const styleOptions = {
            botAvatarImage: 'https://docs.microsoft.com/en-us/azure/bot-service/v4sdk/media/logo_bot.svg?view=azure-bot-service-4.0',
            botAvatarInitials: 'BF',
            userAvatarImage: 'https://avatars1.githubusercontent.com/u/45868722?s=96&v=4',
            userAvatarInitials: 'WC',
            bubbleBackground: 'rgba(0, 0, 255, .1)',
            bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
        };

        // We are using a customized store to add hooks to connect event
        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 }
            }
            });
        }
        return next(action);
        });

        window.WebChat.renderWebChat({
          directLine: window.WebChat.createDirectLine({ token }),
          styleOptions
        }, document.getElementById('webchat'));

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));
    </script>
  </body>
</html>

Answering your questions 回答你的问题

a. 一种。 Correct. 正确。 POST method is not working because there wasn't a token server at the link you were using. POST方法不起作用,因为您使用的链接上没有令牌服务器。

b. b。 Use the code I have above 使用我上面的代码

c. C。 Yes, you can style however you want. 是的,您可以根据需要设置样式。 Welcome messages should work because of the 'DIRECT_LINE/CONNECT_FULFILLED' code. 由于出现'DIRECT_LINE/CONNECT_FULFILLED'代码,因此欢迎消息应该起作用。 You can add additional code from the WebChat samples to accomplish other things, yes. 您可以从WebChat示例中添加其他代码来完成其他事情,是的。

d. d。 Don't use the code that passes "bot" in getElementById . 不要使用在getElementById中传递“ bot”的代码。 Use the code from the WebChat samples or the code I posted 使用WebChat示例中的代码或我发布的代码

e. e。 Remove the post method unless you're using a token server. 除非使用令牌服务器,否则删除post方法。

  1. That's mostly right. 基本上是对的。 See above responses. 请参阅以上回复。

  2. Yes. 是。 Remove the POST method. 删除POST方法。 Your code was very close!! 您的代码非常接近!


Ensure the token you use comes from here: 确保您使用的令牌来自此处:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bot Framework V4 Choice Prompt with Hero Card c# - Bot Framework V4 Choice Prompt with Hero Card c# [BotFrameWork]:如何在使用V4开发的C#Webchat机器人中同时显示文本提示和选择提示? - [BotFrameWork]:How to have text prompt and choice prompt both at a time in C# Webchat bot developed using V4? 如何在 C# 中使用 Microsoft Bot Framework SDK V4 开发的 ChatBot 中添加条件 w.r.t 自适应卡片? - How to add conditions w.r.t Adaptive cards in ChatBot developed using Microsoft Bot Framework SDK V4 in C#? 在 C# 中开发的机器人在微软团队中没有显示自适应卡 - Bot developed in C# not showing Adaptive Card in microsoft teams 更新已在 C# 的 Bot Framework v4 中发布 Adaptive Card - Update already posted Adaptive Card in Bot Framework v4 in C# 如何验证自适应卡片机器人框架 v4(瀑布模型)c# 中的输入字段 - How to validate input fields in adaptive card bot framework v4 (waterfall model) c# 如何修复与使用C#中的V4 SDK开发的聊天机器人窗口中未显示的DirectLineChannel提示选项相关的问题? - How to Fix issues related to DirectLineChannel prompt choice options not displayed in chat bot window developed using V4 SDK in C#? 如何在 Web 频道聊天机器人中显示自适应卡片中的取消按钮,该聊天机器人在 MS Bot 框架 SDK V4 中的 C# 中开发? - How to have cancel button in Adaptive cards to be displayed in Web Channel chat bot developed in MS Bot framework SDK V4 in C#? 单击使用V4 C#开发的chatbot中的自适应卡中的Submit之后,如何解决与Web聊天通道中的500错误代码相关的问题? - How to fix issue related to 500 error code in web chat channel after clicking submit in Adaptive card in chatbot developed using V4 C#? 如何在使用C#创建的SDK V4 bot中的瀑布式对话框中使用oauth提示修复下一步导航而不键入任何内容? - How to fix next step navigation with oauth prompt in waterfall dialog in SDK V4 bot created using C# without typing anything?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM