如何发送临时主动事件

时间:2018-04-10 01:44:37

标签: botframework direct-line-botframework

如何向所有座席发送事件主动消息?

我可以成功向所有代理发送纯文本消息,但我更愿意发送一个事件。

这是我的尝试:

            //Create a new message for sending an event
            var message = Activity.CreateMessageActivity() as Activity;                    

            var conversationId = agent.conversationId;
            message.ChannelId = agent.channelId;


            // Set the address-related properties in the message and send the message.
            message.From = botAccount;
            message.Recipient = agentAccount;
            message.Conversation = new ConversationAccount() { Id = conversationId };

            //Type.Event/backchannel approach
            message.Type = ActivityTypes.Event;
            message.Name = "newCustomerOnHoldAlert";
            message.Value = System.Web.HttpUtility.HtmlEncode(customerEmail);
            await connector.Conversations.SendToConversationAsync((Activity)message);

以下是对应的javascript:

                    botConnection.activity$
                        .filter(activity => activity.type === "event")
                        .subscribe(activity => doActivity(activity));

                    function doActivity(activity) {
                        console.log(activity.name);
                        switch (activity.name) {
                            case "newCustomerOnHoldAlert":
                                console.log("in newCustomerOnHoldAlert")
                                break;

                            default:
                                console.log("doActivity() did nothing.")
                                break;
                        }
                    }

这与my previous question about how to intercept receiving proactive messages有关。我想探讨两种选择。

0 个答案:

没有答案