【发布时间】:2019-09-18 03:02:02
【问题描述】:
我已经将机器人部署到 azure,当连接到 azure 中的 ms 团队频道时,我能够 ping 机器人并接收消息,这很好。 我还在 bot 中添加了主动消息传递,其中将在频道中每分钟触发一条消息。
它在模拟器中工作,但在网络聊天和 MS 团队中不工作: 未触发通知控制器。
你能帮我解决这个问题吗? 我已经在 GITHUB 中上传了代码: https://github.com/nivinsunathree/Botv4.git
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
await base.OnTurnAsync(turnContext, cancellationToken);
System.Timers.Timer checkForTime = new System.Timers.Timer(interval60Minutes);
checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
checkForTime.Enabled = true;
// Save any state changes that might have occured during the turn.
await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await _userState.SaveChangesAsync(turnContext, false, cancellationToken);
}
void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
bool timeIsReady = true;
if (timeIsReady == true)
{
var url = "http://localhost:3978/api/notify";
try
{
Process.Start(url);
}
catch
{
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = false });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}
}
一分钟后,应该会在频道中触发以下消息:
await turnContext.SendActivityAsync(MessageFactory.Text($"Hello!" + Environment.NewLine + $"Trust you are well" + Environment.NewLine + $"Hope that you are having a good day" + Environment.NewLine + $"We are contacting you concerning lea access requests" + Environment.NewLine + $"Could you please review the following tasks if any and add the required information!"), cancellationToken);
//await turnContext.SendActivityAsync(MessageFactory.Text($"Please type ok to continue!"), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Text("Could you please click on the below button to continue?"));
var card = new HeroCard
{
//Text = "Could you please click on the below button to continue?",
Buttons = new List<CardAction>
{
new CardAction(ActionTypes.ImBack, title: "lea access request", value: "lea access request"),
},
};
var reply = MessageFactory.Attachment(card.ToAttachment());
await turnContext.SendActivityAsync(reply, cancellationToken);
【问题讨论】:
标签: c# botframework microsoft-teams