首页 文章

Microsoft Bot Framework渠道集成:更多 endpoints ?

提问于
浏览
0

我正在使用Microsoft Bot Framework使用 Channels 注册产品和REST API . 我已经设置了“消息传递 endpoints ”,一切都可以正常发送和接收消息 .

但我不只是想发送/接收消息 . 设置欢迎消息这样简单的事情似乎是不可能的,因为我的 endpoints 只接收消息传递事件(当机器人在 Channels /会话中时) .

有没有我错过的东西?

我想设置几个 endpoints ,或者使用相同的 endpoints 来监听其他类型的事件 .

1 回答

  • 0

    你需要在MessageController中实现这样的东西:在else if中注意 . 控制器中的功能是HandleSystemMessage .

    else if(message.Type == ActivityTypes.ConversationUpdate){

    // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels
                IConversationUpdateActivity update = message;
                var cliente = new ConnectorClient(new System.Uri(message.ServiceUrl), new MicrosoftAppCredentials());
    
                if (update.MembersAdded != null && update.MembersAdded.Count > 0)
                {
                    foreach(var member in update.MembersAdded)
                    {
                        if(member.Id != message.Recipient.Id)
                        {
                            //var username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                            var username = message.From.Name;
                            var reply = message.CreateReply();
                            //string dir = System.AppDomain.CurrentDomain.BaseDirectory + "Images" + Path.DirectorySeparatorChar + "cajamar.png";
                            string dir = HttpRuntime.AppDomainAppPath + "Images" + Path.DirectorySeparatorChar + "cajamar.png";
    
                            reply.Attachments.Add(new Attachment(
                                    contentUrl: dir,
                                    contentType: "image/png",
                                    name: "cajamar.png"
                                ));
                            reply.Text = $"Bienvenido {username} al ChatBot de convenios:";
                            cliente.Conversations.ReplyToActivity(reply);
                            //var reply = message.CreateReply();
    
                            //reply.Text = $"El directorio base es: {HttpRuntime.AppDomainAppPath}";
                            //cliente.Conversations.ReplyToActivityAsync(reply);
                        }
                    }
                }
            }
    

相关问题