我正在开发一种机器人,它将代替公司的联系表格。当有人使用漫游器时,开发人员或公司是否有一种简单的方法来获得通知?我正在使用Microsoft Bot Framework和cosmosDB来存储状态数据。
答案 0 :(得分:0)
有两种方法可以做到这一点。在我的头顶上:
您可以将电子邮件设置为机器人的通道,但这仅意味着用户将通过电子邮件与您的机器人进行通信。但是您可以通过此电子邮件跟踪客户联系人。
否则,正如上面的D4CKCIDE所述,您可以嵌入一些简单的逻辑以在机器人逻辑中击中某个特定流程后立即发出通知。例如,我嵌入了一个快速功能,可以在点击“ conversationUpdate”活动后立即将电子邮件从一个电子邮件地址发送到另一个电子邮件地址(在这种情况下,是从我的Outlook电子邮件发送到我的gmail),因为这意味着新用户已与我的机器人。它并不能将全部历史发送给我,而只是作为提醒来进行ping,以进行跟踪:
else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
{
if (turnContext.Activity.MembersAdded != null)
{
// Iterate over all new members added to the conversation
foreach (var member in turnContext.Activity.MembersAdded)
{
// Greet anyone that was not the target (recipient) of this message
// the 'bot' is the recipient for events from the channel,
// turnContext.Activity.MembersAdded == turnContext.Activity.Recipient.Id
// indicates the bot was added to the conversation.
if (member.Id != turnContext.Activity.Recipient.Id)
{
await turnContext.SendActivityAsync($"Hi there - {member.Name}. {WelcomeMessage}", cancellationToken: cancellationToken);
await turnContext.SendActivityAsync(InfoMessage, cancellationToken: cancellationToken);
await turnContext.SendActivityAsync(PatternMessage, cancellationToken: cancellationToken);
}
EmailPingFunction();
}
}
}
然后我按如下所示构建了EmailPingFunction:
private static void EmailPingFunction()
{
// setup strings
string sender = "BotsyJohnson@outlook.com";
string password = "********"; // put your email's password here ^_^
string recipient = "BotsyJohnson@gmail.com";
// set the client:
SmtpClient outlookSmtp = new SmtpClient("smtp-mail.outlook.com");
// use the 587 TLS port
outlookSmtp.Port = 587;
// set the delivery method
outlookSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
// set the credentials
outlookSmtp.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(sender, password);
outlookSmtp.Credentials = credentials;
// enable SS1
outlookSmtp.EnableSsl = true;
// set up and send the MailMessage
try
{
Console.WriteLine("start to send email over TLS...");
MailMessage message = new MailMessage(sender, recipient);
message.Subject = "This is a test of the not-emergency alert system";
message.Body = "Someone just pinged your bot. Please go into your set storage account to review";
outlookSmtp.Send(message);
Console.WriteLine("email was sent successfully!");
}
catch (Exception ex)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ex.Message);
}
}
仅需强调Nicholas R.所说的话,因为他是绝对正确的:这是自定义的,并且只是您如何进行此操作的一种选择。这是您创建某种通知的一种卑鄙而肮脏的选择。