【发布时间】:2021-02-25 15:13:18
【问题描述】:
我的代码:
# load card .json
card_path = os.path.join(os.getcwd(), "resources", "test.json")
with open(card_path, "rb") as in_file:
card_data = json.load(in_file)
# create card
card = CardFactory.adaptive_card(card_data)
# target channel
thread_id = "19:95a25b4767123e29f835d3c10e88f1ee@thread.tacv2"
# create connector client
client = await ADAPTER.create_connector_client(service_url="https://smba.trafficmanager.net/emea/")
message = Activity(
text="Here is an Adaptive Card:",
type=ActivityTypes.message,
attachments=[card],
)
params = ConversationParameters(
is_group=True,
channel_data={"channel": {"id": thread_id}},
activity=message
)
# send card
return await client.conversations.create_conversation(params)
错误:(BadSyntax)活动导致多个 Skype 活动
Traceback (most recent call last):
File "/home/user/apps/pycharm-2018.1.3/helpers/pydev/pydevd.py", line 1664, in <module>
main()
[...]
File "/home/user/PycharmProjects/foo/07.using-adaptive-cards/venv/lib/python3.8/site-packages/aiohttp/signals.py", line 34, in send
await receiver(*args, **kwargs) # type: ignore
File "/home/user/PycharmProjects/foo/07.using-adaptive-cards/app.py", line 114, in startup
return await client.conversations.create_conversation(params)
File "/home/user/PycharmProjects/foo/07.using-adaptive-cards/venv/lib/python3.8/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) Activity resulted into multiple skype activities
我的自适应卡是正确的。我尝试了 Microsoft 提供的示例项目07.using-adaptive-cards,但是此示例不适用于主动消息。它(只是)响应聊天消息。
class AdaptiveCardsBot(ActivityHandler):
async def on_message_activity(self, turn_context: TurnContext):
card_path = os.path.join(os.getcwd(), "resources", "test.json")
with open(card_path, "rb") as in_file:
card_data = json.load(in_file)
card = CardFactory.adaptive_card(card_data)
message = Activity(
text="Here is an Adaptive Card:",
type=ActivityTypes.message,
attachments=[card],
)
await turn_context.send_activity(message)
我需要主动发送一张自适应卡片。
我可以像下面这样定期发送主动的 Teams 消息,那为什么不发送卡片呢?
message = "Hello channel"
thread_id = "19:95a25b4767123e29f835d3c10e88f1ee@thread.tacv2"
client = await ADAPTER.create_connector_client(service_url="https://smba.trafficmanager.net/emea/")
params = ConversationParameters(
is_group=True,
channel_data={"channel": {"id": thread_id}},
activity=MessageFactory.text(message)
)
await client.conversations.create_conversation(params)
我查看了https://stackoverflow.com/a/62099293/14997633 此处给出的答案,但这似乎将原始数据发送到 URL,我更喜欢使用 Botframework v4 提供的实用程序/工具。
【问题讨论】:
标签: python-3.x botframework microsoft-teams