【问题标题】:I want to trigger mail when the bot says that it has no answer当机器人说它没有答案时,我想触发邮件
【发布时间】:2019-06-16 00:56:53
【问题描述】:

我想在机器人说没有答案时触发邮件。

我正在使用 MS bot 框架 SDk4,并且还使用 LUIS 和 QnA 制造商,当机器人到达它说它没有答案的地步时,我们希望触发邮件或在其中添加新项目共享点

【问题讨论】:

标签: email botframework


【解决方案1】:

如果您想向 SharePoint 列表添加“否”答案,我设法使用 csom-node 包和 Bot Framework v4 / NodeJS 使其正常工作。当然,这不是最优雅的解决方案,但它确实有效。

Bot.JS

const csomapi = require('../node_modules/csom-node');
settings = require('../settings').settings;

// Set CSOM settings
csomapi.setLoaderOptions({url: settings.siteurl});

页面再往下一点...

// If no answers were returned from QnA Maker, reply with help.
            } else {
                await context.sendActivity("Er sorry, I don't seem to have an answer.");
                console.log(context.activity.text);
                var response = context.activity.text;
                var authCtx = new AuthenticationContext(settings.siteurl);
                authCtx.acquireTokenForApp(settings.clientId, settings.clientSecret, function (err, data) {

                    var ctx = new SP.ClientContext("/sites/yoursite");  //set root web
                    authCtx.setAuthenticationCookie(ctx);  //authenticate
                        var web = ctx.get_web();
                        var list = web.get_lists().getByTitle('YourList');
                        var creationInfo = new SP.ListItemCreationInformation();
                        var listItem = list.addItem(creationInfo);
                        listItem.set_item('Title', response);
                        listItem.update();
                        ctx.load(listItem);
                        ctx.executeQueryAsync();
                });
            }

【讨论】:

    【解决方案2】:

    Proactive Messaging真的不适用于电子邮件(以防止垃圾邮件),因此最好不要将 Bot Framework SDK 用于电子邮件部分。 @Baruch 的链接 How to send email in ASP.NET C# 如果您使用的是 C# SDK,则很好。这是sending emails in Node 的一个。

    您只需在 QnA Maker 未返回任何结果时发送电子邮件即可。在this sample,你会这样做here

    if (response != null && response.Length > 0)
    {
        await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
    }
    else
    {
        await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
    
        // Add code that sends Notification Email
    
    }
    

    话虽如此,如果您想尝试半主动路由,可以在您的机器人中启用电子邮件通道,然后使用:

    if (response != null && response.Length > 0)
    {
        await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
    }
    else
    {
        await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
    
        MicrosoftAppCredentials.TrustServiceUrl(@"https://email.botframework.com/", DateTime.MaxValue);
    
        var user = new ChannelAccount(name: "MyUser", id: "<notified Email Address>");
        var parameters = new ConversationParameters()
        {
            Members = new ChannelAccount[] { user },
            Bot = turnContext.Activity.Recipient
        };
        var connector = new ConnectorClient(new Uri("https://email.botframework.com"), "<appId>", "<appPassword>");
        var conversation = await connector.Conversations.CreateConversationAsync(parameters);
    
        var activity = MessageFactory.Text("This is a notification email");
        activity.From = parameters.Bot;
        activity.Recipient = user;
    
        await connector.Conversations.SendToConversationAsync(conversation.Id, activity);
    
    }
    

    问题是&lt;notified Email Address&gt; 必须先向机器人发送消息,然后通知才会起作用。如果没有,它将返回 401: Unauthorized 错误。同样,我不推荐这条路线。


    注意:如果您使用的是 Dispatch 示例,请输入代码 here

    private async Task ProcessSampleQnAAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
            {
                _logger.LogInformation("ProcessSampleQnAAsync");
    
                var results = await _botServices.SampleQnA.GetAnswersAsync(turnContext);
                if (results.Any())
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken);
                }
                else
                {
                    // PLACE IT HERE
                    await turnContext.SendActivityAsync(MessageFactory.Text("Sorry, could not find an answer in the Q and A system."), cancellationToken);
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 2021-08-02
      • 2021-05-20
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2023-02-17
      相关资源
      最近更新 更多