可以在没有azure或漫游器模拟器的情况下在自己的客户端中测试漫游器吗?

可以在没有azure或漫游器模拟器的情况下在自己的客户端中测试漫游器吗?,第1张

概述我是新来的.我已经检查了已经问过的问题,但找不到适合我的情况的答案.查询:我试图在本地创建一个机器人,在文档的帮助下我成功了.我可以在bot模拟器中进行测试.现在,我想在wpf中创建自己的客户端,我在网上找到的所有示例都具有来自Azure的直接秘密.但是,仿真器在没有互联网的情况下工作,所以我想,他们一定是在做秘密 *** 作.由于我是wpf应用程序开发人员,因此我

我是新来的.我已经检查了已经问过的问题,但找不到适合我的情况的答案.

查询:
我试图在本地创建一个机器人,在文档的帮助下我成功了.我可以在bot模拟器中进行测试.现在,我想在wpf中创建自己的客户端,我在网上找到的所有示例都具有来自Azure的直接秘密.但是,仿真器在没有互联网的情况下工作,所以我想,他们一定是在做秘密 *** 作.

由于我是wpf应用程序开发人员,因此我无法理解模拟器源代码或使其无法运行.

谁能告诉我或指出在哪里可以检查如何在没有azure direcltline机密的情况下在本地运行bot客户端?

机器人

[BotAuthentication]public class MessagesController : APIController{    /// <summary>    /// POST: API/Messages    /// Receive a message from a user and reply to it    /// </summary>    public async Task<httpResponseMessage> Post([FromBody]Activity activity)    {        if (activity.Type == ActivityTypes.Message)        {            await Conversation.SendAsync(activity,() => new DirectlineBotDialog());        }        else        {            await HandleSystemMessage(activity);        }        var response = Request.CreateResponse(httpStatusCode.OK);        return response;    }    private async Task HandleSystemMessage(Activity message)    {        if (message.Type == ActivityTypes.DeleteUserData)        {            // Implement user deletion here            // If we handle user deletion,return a real message        }        else if (message.Type == ActivityTypes.ConversationUpdate)        {            // Handle conversation state changes,like members being added and removed            // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info            // Not available in all channels            if (message.MembersAdded.Any(o => o.ID == message.RecipIEnt.ID))            {                ConnectorClIEnt clIEnt = new ConnectorClIEnt(new Uri(message.ServiceUrl));                var reply = message.CreateReply();                reply.Text = "Welcome to the Bot to showcase the Directline API. Send 'Show me a hero card' or 'Send me a BotFramework image' to see how the Directline clIEnt supports custom channel data. Any other message will be echoed.";                await clIEnt.Conversations.ReplyToActivityAsync(reply);            }        }        else if (message.Type == ActivityTypes.ContactRelationUpdate)        {            // Handle add/remove from contact Lists            // Activity.From + Activity.Action represent what happened        }        else if (message.Type == ActivityTypes.TyPing)        {            // Handle kNowing tha the user is tyPing        }        else if (message.Type == ActivityTypes.Ping)        {        }    }}

客户:

 class Program{    private static string directlinesecret = ConfigurationManager.AppSettings["Directlinesecret"];    private static string botID = ConfigurationManager.AppSettings["BotID"];    private static string fromUser = "DirectlinesampleClIEntUser";    static voID Main(string[] args)    {        StartBotConversation().Wait();    }    private static async Task StartBotConversation()    {        DirectlineClIEnt clIEnt = new DirectlineClIEnt(directlinesecret);        var conversation = await clIEnt.Conversations.StartConversationAsync();        new System.Threading.Thread(async () => await ReadBotMessagesAsync(clIEnt,conversation.ConversationID)).Start();        Console.Write("Command> ");        while (true)        {            string input = Console.Readline().Trim();            if (input.Tolower() == "exit")            {                break;            }            else            {                if (input.Length > 0)                {                    Activity userMessage = new Activity                    {                        From = new ChannelAccount(fromUser),Text = input,Type = ActivityTypes.Message                    };                    await clIEnt.Conversations.PostActivityAsync(conversation.ConversationID,userMessage);                }            }        }    }    private static async Task ReadBotMessagesAsync(DirectlineClIEnt clIEnt,string conversationID)    {        string watermark = null;        while (true)        {            var activitySet = await clIEnt.Conversations.GetActivitIEsAsync(conversationID,watermark);            watermark = activitySet?.Watermark;            var activitIEs = from x in activitySet.ActivitIEs                             where x.From.ID == botID                             select x;            foreach (Activity activity in activitIEs)            {                Console.Writeline(activity.Text);                if (activity.Attachments != null)                {                    foreach (Attachment attachment in activity.Attachments)                    {                        switch (attachment.ContentType)                        {                            case "application/vnd.microsoft.card.hero":                                RenderHeroCard(attachment);                                break;                            case "image/png":                                Console.Writeline($"opening the requested image '{attachment.ContentUrl}'");                                Process.Start(attachment.ContentUrl);                                break;                        }                    }                }                Console.Write("Command> ");            }            await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);        }    }    private static voID RenderHeroCard(Attachment attachment)    {        const int WIDth = 70;        Func<string,string> contentline = (content) => string.Format($"{{0,-{WIDth}}}",string.Format("{0," + ((WIDth + content.Length) / 2).ToString() + "}",content));        var heroCard = JsonConvert.DeserializeObject<HeroCard>(attachment.Content.ToString());        if (heroCard != null)        {            Console.Writeline("/{0}",new string('*',WIDth + 1));            Console.Writeline("*{0}*",contentline(heroCard.Title));            Console.Writeline("*{0}*",new string(' ',WIDth));            Console.Writeline("*{0}*",contentline(heroCard.Text));            Console.Writeline("{0}/",WIDth + 1));        }    }}

如果我做错了任何事情,请让我知道.

预先感谢

最佳答案看一下我的同事Ryan Volum的the excellent Offline DirectLine node package.不要仅仅因为您正在编写基于.NET的bot而让它基于Node的事实阻止您.它所做的就是在本地Web服务器上站起来,该服务器模仿Directline API并将请求通过隧道传送到您的机器人.

使用非常简单,只需遵循the usage directions on the package page. 总结

以上是内存溢出为你收集整理的可以在没有azure或漫游器模拟器的情况下在自己的客户端中测试漫游器吗? 全部内容,希望文章能够帮你解决可以在没有azure或漫游器模拟器的情况下在自己的客户端中测试漫游器吗? 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1244301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存