如何使用 BotAuthentication botframework v3

How to use BotAuthentication botframework v3

我正在尝试根据 this 发出主动消息。

我能理解它的方法。我担心安全问题。所以我正在尝试使用 BotAuthentication。但我不知道如何使用它。我尝试根据 this.

添加令牌

不过好像没什么用。如何使用BotAuthentication?对了,我需要担心安全问题吗?

using Bot.Dialogs.FAQ.Liquidation;
using Bot.Dialogs.Menu;
using Bot.Resources;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Resources;
using System.Threading.Tasks;
using System.Web.Http;

namespace Bot
{
    [BotAuthentication]
    public class CustomWebAPIController : ApiController
    {

        [HttpGet]
        [Route("api/CustomWebAPI")]
        public async Task<HttpResponseMessage> SendMessage()
        {
            try
            {
                if (!string.IsNullOrEmpty(ConversationStarter.conversationReference))
                {
                    await ConversationStarter.Resume(); //We don't need to wait for this, just want to start the interruption here

                    var resp = new HttpResponseMessage(HttpStatusCode.OK);
                    resp.Content = new StringContent($"<html><body>Message sent, thanks.</body></html>", System.Text.Encoding.UTF8, @"text/html");
                    return resp;
                }
                else
                {
                    var resp = new HttpResponseMessage(HttpStatusCode.OK);
                    resp.Content = new StringContent($"<html><body>You need to talk to the bot first so it can capture your details.</body></html>", System.Text.Encoding.UTF8, @"text/html");
                    return resp;
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }
        }

    }
}

您不需要处理机器人身份验证。这是由 SDK 完成的。

您不应使用 v3,因为它已被弃用且不再开发。 V4 是当前版本。

Here 是关于 V4 主动消息的文档。

here 是一个示例,展示了如何使用主动消息。