简体   繁体   中英

Skype calling bot example

I just developed a demo skype calling bot, following the example posted in [SDK reference]. I published the project in Azure and I registered in the portal on the skype channel, updating the related page. If I chat with the bot on Skype, everything is working fine, but if I try a skype call, instead of the message I espect, I get a voice message "Can't talk to this project yet, but we are working on it". Is this is because there is an approval process ongoing or I am missing some step?

Here is CallingController code:

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 } };
        }
    }
}

Based on your comments, I believe the issue is with the URL you used when enabling the Skype channel. The Calling WebHook URL configured in the Skype settings of the Bot Framework should be, based on your url, https://skyva.azurewebsites.net/api/calling/call .

Your CallingController should looks like:

[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);
    }
}

I solved the issue, in the skype bot configuration I had to specify the calling endpoint and not the callback. Now the bot is working correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM