【问题标题】:Skype calling bot exampleSkype 通话机器人示例
【发布时间】:2017-03-12 14:48:53
【问题描述】:

我刚刚按照 [SDK 参考] 中发布的示例开发了一个演示 Skype 呼叫机器人。我在 Azure 中发布了项目,并在 Skype 频道的门户中注册,更新了相关页面。 如果我在 Skype 上与机器人聊天,一切正常,但如果我尝试 Skype 通话,而不是我所关注的消息,我会收到一条语音消息“还不能与这个项目交谈,但我们正在处理它”。 这是因为正在进行审批流程还是我遗漏了一些步骤?

这是 CallingController 代码:

using Microsoft.Bot.Builder.Calling;
using Microsoft.Bot.Builder.Calling.Events;
using Microsoft.Bot.Builder.Calling.ObjectModel.Contracts;
using Microsoft.Bot.Builder.Calling.ObjectModel.Misc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Web;

namespace skyva
{
    public class SimpleCallingBot : ICallingBot
    {
        public ICallingBotService CallingBotService
        {
            get; private set;
        }

        public SimpleCallingBot(ICallingBotService callingBotService)
        {
            if (callingBotService == null)
                throw new ArgumentNullException(nameof(callingBotService));
            this.CallingBotService = callingBotService;
            CallingBotService.OnIncomingCallReceived += OnIncomingCallReceived;
            CallingBotService.OnPlayPromptCompleted += OnPlayPromptCompleted;
            CallingBotService.OnRecognizeCompleted += OnRecognizeCompleted;
            CallingBotService.OnRecordCompleted += OnRecordCompleted;
            CallingBotService.OnHangupCompleted += OnHangupCompleted;
        }

        private Task OnIncomingCallReceived(IncomingCallEvent incomingCallEvent)
        {
            var id = Guid.NewGuid().ToString();
            incomingCallEvent.ResultingWorkflow.Actions = new List<ActionBase>
                {
                    new Answer { OperationId = id },
                    GetPromptForText("Hello, this is skiva, your virtual assistant on skype")
                };
            return Task.FromResult(true);
        }

        private Task OnPlayPromptCompleted(PlayPromptOutcomeEvent playPromptOutcomeEvent)
        {
            playPromptOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
            {
                CreateIvrOptions("Say yes if you want to know current weather conditions, otherwise say no", 2, false)
            };
            return Task.FromResult(true);
        }

        private Task OnRecognizeCompleted(RecognizeOutcomeEvent recognizeOutcomeEvent)
        {
            switch (recognizeOutcomeEvent.RecognizeOutcome.ChoiceOutcome.ChoiceName)
            {
                case "Yes":
                    recognizeOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                    {
                        GetPromptForText("Current weather is sunny!"),
                        new Hangup { OperationId = Guid.NewGuid().ToString() }
                    };
                    break;
                case "No":
                    recognizeOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                    {
                        GetPromptForText("At the moment I don't have other options. Goodbye!"),
                        new Hangup { OperationId = Guid.NewGuid().ToString() }
                    };
                    break;
                default:
                    recognizeOutcomeEvent.ResultingWorkflow.Actions = new List<ActionBase>
                    {
                        CreateIvrOptions("Say yes if you want to know weather conditions, otherwise say no", 2, false)
                    };
                    break;
            }
            return Task.FromResult(true);
        }


        private Task OnHangupCompleted(HangupOutcomeEvent hangupOutcomeEvent)
        {
            hangupOutcomeEvent.ResultingWorkflow = null;
            return Task.FromResult(true);
        }

        private static Recognize CreateIvrOptions(string textToBeRead, int numberOfOptions, bool includeBack)
        {            
            var id = Guid.NewGuid().ToString();
            var choices = new List<RecognitionOption>();
            choices.Add(new RecognitionOption
            {
                Name = "Yes",
                SpeechVariation = new List <string>() { "Yes", "Okay" }
        });
            choices.Add(new RecognitionOption
            {
                Name = "No",
                SpeechVariation = new List<string>() { "No", "None" }
            });

            var recognize = new Recognize
            {
                OperationId = id,
                PlayPrompt = GetPromptForText(textToBeRead),
                BargeInAllowed = true,
                Choices = choices
            };
            return recognize;
        }

        private static PlayPrompt GetPromptForText(string text)
        {
            var prompt = new Prompt { Value = text, Voice = VoiceGender.Male };
            return new PlayPrompt { OperationId = Guid.NewGuid().ToString(), Prompts = new List<Prompt> { prompt } };
        }
    }
}

【问题讨论】:

  • 调用和回调的URL配置好了吗?
  • 在 web.config 中我指定了'code' skyva.azurewebsites.net/api/calling/callback" /> 并在机器人注册中我指定了@ 987654322@ 作为调用回调。我没有为通话网址指定任何内容。我应该在哪里做?
  • 对...注册的那个错了。应该是skyva.azurewebsites.net/api/calling/call。我会发布一个更详细的答案

标签: azure botframework skype


【解决方案1】:

根据您的 cmets,我认为问题出在您启用 Skype 频道时使用的 URL。根据您的 url,在 Bot Framework 的 Skype 设置中配置的 Calling WebHook URL 应为https://skyva.azurewebsites.net/api/calling/call

您的CallingController 应如下所示:

[BotAuthentication]
[RoutePrefix("api/calling")]
public class CallingController : ApiController
{
    public CallingController() : base()
    {
        CallingConversation.RegisterCallingBot(callingBotService => new SimpleCallingBot(callingBotService));
    }

    [Route("callback")]
    public async Task<HttpResponseMessage> ProcessCallingEventAsync()
    {
        return await CallingConversation.SendAsync(this.Request, CallRequestType.CallingEvent);
    }

    [Route("call")]
    public async Task<HttpResponseMessage> ProcessIncomingCallAsync()
    {
        return await CallingConversation.SendAsync(this.Request, CallRequestType.IncomingCall);
    }
}

【讨论】:

    【解决方案2】:

    我解决了这个问题,在 Skype 机器人配置中,我必须指定调用端点而不是回调。现在机器人可以正常工作了。

    【讨论】:

    • 我之前已经发布了答案。请标记为已回答。
    猜你喜欢
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2018-05-02
    • 2014-07-29
    • 2018-02-14
    • 2019-08-03
    相关资源
    最近更新 更多