我刚刚根据[SDK参考]中发布的示例开发了一个演示skype调用bot。我在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 } };
}
}
}
答案 0 :(得分:1)
根据您的评论,我认为问题在于启用Skype频道时使用的网址。在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);
}
}
答案 1 :(得分:0)
我解决了这个问题,在skype bot配置中我必须指定调用端点而不是回调。现在机器人正常工作。