.net core Bot Framework.Net Core从IFrame获取字符串变量

.net core Bot Framework.Net Core从IFrame获取字符串变量,.net-core,botframework,bots,azure-language-understanding,azure-bot-service,.net Core,Botframework,Bots,Azure Language Understanding,Azure Bot Service,问题在于使用.NETCore通过Bot框架创建Bot应用程序。 在.NETFramework中,我使用API创建了Bot应用程序。在初始方法中,我传递字符串参数并从iframeURL获取该值,但在.NETCore中,我使用OnTurnAsync方法,不能重写该方法以“userName”的形式传递字符串参数。 我在下面分享.Net核心和.Net框架的初始方法 我通过IFrame调用bot应用程序,例如; https://webchat.botframework.com/...&userName=t

问题在于使用.NETCore通过Bot框架创建Bot应用程序。 在.NETFramework中,我使用API创建了Bot应用程序。在初始方法中,我传递字符串参数并从iframeURL获取该值,但在.NETCore中,我使用OnTurnAsync方法,不能重写该方法以“userName”的形式传递字符串参数。 我在下面分享.Net核心和.Net框架的初始方法

我通过IFrame调用bot应用程序,例如; https://webchat.botframework.com/...&userName=test'style=“宽度:600px;高度:600px;”>

那个么,如何将参数传递给OnTurnAsync方法呢

.Net框架

   public async Task<HttpResponseMessage> Post([FromBody]Activity activity, string userName)
    {
        if (activity.Type == ActivityTypes.Message)
        {                
            var keyword = activity.Text.ToLower().ToEnglish();
            var responseAttachment = KeywordHelper.GetAttachmentResult(keyword);
            if (responseAttachment != null)
            {
                var answer = ((HeroCard)responseAttachment.Content).Title.ToString();
                conversation.Response = answer;
                this.conversationService.InsertToConversation(conversation);
                var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                var reply = activity.CreateReply();
                reply.Attachments.Add(responseAttachment);
                await connector.Conversations.ReplyToActivityAsync(reply);

                activity.Type = ActivityTypes.Message;
            }
        }
    }

您仍然可以在BotBuilder V4中使用Web Api控制器,如本例所示:


但是,如果您将userid和username作为查询字符串参数传递给WebChat iframe,那么您可以从
活动中检索用户名。从.Name

您仍然可以使用V4的控制器,如本mvc示例所示:因此,我认为应该过度使用OnTurnAsync方法从iframe获取username参数,但是我不能。如何在初始方法中获取用户名参数?如果您只需要用户名,则可以从activity.from.Name中检索它(userid和userName是webchat将从url字符串传递到activity中的两个参数)。
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                var userName = "userName";

                var keyword = turnContext.Activity.Text.ToLower().ToEnglish();
                var responseAttachment = KeywordHelper.GetAttachmentResult(keyword);

                if (responseAttachment != null)
                {
                    var answer = ((HeroCard)responseAttachment.Content).Title.ToString();
                    conversation.Response = answer;
                    this.conversationService.InsertToConversation(conversation);
                    var connector = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl));


                    var reply = turnContext.Activity.CreateReply();
                }

            }
    }
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
    private readonly IBotFrameworkHttpAdapter Adapter;
    private readonly IBot Bot;

    public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
    {
        Adapter = adapter;
        Bot = bot;
    }

    [HttpPost]
    public async Task PostAsync()
    {
        // Delegate the processing of the HTTP POST to the adapter.
        // The adapter will invoke the bot.
        await Adapter.ProcessAsync(Request, Response, Bot);
    }
}