【问题标题】:Initial and send a message to a Microsoft Teams channel using Bot Framework SDK v4 for Python使用适用于 Python 的 Bot Framework SDK v4 初始化并向 Microsoft Teams 频道发送消息
【发布时间】:2020-05-01 11:25:34
【问题描述】:

我试图在以下示例的帮助下初始化并向一个 Microsoft 团队频道发送 proactive 消息: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/python/16.proactive-messages 我将此代码添加到示例中以启动消息:

connectorClient = await ADAPTER.create_connector_client(service_url=SERVICE_URL)
parameters = ConversationParameters(
        is_group=True,
        channel_data=CHANNEL_ID,
        activity=Activity(type=ActivityTypes.message,
        text='Hello World!'),
        bot=ChannelAccount(id=BOT_ID),
        tenant_id=TENANT_ID)
response = await connectorClient.conversations.create_conversation(parameters)
response.send()

但它没有用,我尝试了很多不同的方法,但它们都没有奏效,总是错误是:

Traceback (most recent call last):
File "/home/farid/works/16.proactive-messages/venv/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/home/farid/works/16.proactive-messages/venv/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/home/farid/works/16.proactive-messages/app.py", line 103, in notify
raise exception
File "/home/farid/works/16.proactive-messages/app.py", line 100, in notify
await _send_proactive_message()
File "/home/farid/works/16.proactive-messages/app.py", line 152, in _send_proactive_message
response = await connectorClient.conversations.create_conversation(parameters)
File "/home/farid/works/16.proactive-messages/venv/lib/python3.7/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 176, in create_conversation
raise models.ErrorResponseException(self._deserialize, response)
botbuilder.schema._models_py3.ErrorResponseException: (BadSyntax) Incorrect conversation creation parameters

我不知道我的问题是什么!

【问题讨论】:

    标签: python botframework microsoft-teams


    【解决方案1】:

    有一个非常很好的机会,因为我以前从未尝试过阅读 Python(我是 C#/node 人),但它看起来像,在您的 ConversationParameters 中,您缺少“收件人”详细信息(您指定了“发件人”,即您的 Bot),通常需要为此指定。

    这很有帮助...

    【讨论】:

    • 谢谢,但我也在 "BotBuilder" GitHub 上关注这个问题,据我所知,他们的 C# 代码上没有任何内容,比如你提到的东西,所以我希望有人能洞察我们是什么问题!
    【解决方案2】:

    这是使用 sdk 3 的 C# 示例代码

            var userId = userOrChannelId.Trim();
            var botId = context.Activity.Recipient.Id;
            var botName = context.Activity.Recipient.Name;
    
            var channelData = context.Activity.GetChannelData<TeamsChannelData>();
            var connectorClient = new ConnectorClient(new Uri(context.Activity.ServiceUrl));
            var parameters = new ConversationParameters
            {
                Bot = new ChannelAccount(botId, botName),
                Members = !isChannelMessage ? new ChannelAccount[] { new ChannelAccount(userId) } : null,
                ChannelData = new TeamsChannelData
                {
                    Tenant = channelData.Tenant,
                    Channel = isChannelMessage ? new ChannelInfo(userId) : null,
                    Notification = new NotificationInfo() { Alert = true }
                },
                IsGroup = isChannelMessage
            };
    
    
                var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters);
                var replyMessage = Activity.CreateMessageActivity();
                replyMessage.From = new ChannelAccount(botId, botName);
                replyMessage.Conversation = new ConversationAccount(id: conversationResource.Id.ToString());
                replyMessage.ChannelData = new TeamsChannelData() { Notification = new NotificationInfo(true) };
                replyMessage.Text = messageText;
                if (attachment != null)
                    replyMessage.Attachments.Add(attachment);
    
                    var resourceResponse = await connectorClient.Conversations.SendToConversationAsync(conversationResource.Id, (Activity)replyMessage);
    

    【讨论】:

      【解决方案3】:

      好的,昨晚微软添加了一个新的 python 示例来解决这个问题: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/python/58.teams-start-thread-in-channel

      【讨论】:

        猜你喜欢
        • 2019-04-22
        • 1970-01-01
        • 2020-05-07
        • 1970-01-01
        • 2021-07-26
        • 1970-01-01
        • 2020-11-10
        • 2019-08-23
        • 1970-01-01
        相关资源
        最近更新 更多