简体   繁体   English

我无法从Microsoft Teams bot向另一个用户发送消息

[英]I can't send a message to another user from Microsoft Teams bot

It is impossible to send a message to another user from the bot in Microsoft Teams. 无法从Microsoft Teams中的机器人向另一个用户发送消息。 It constantly sends messages to me although all the parameters are passed from the database. 虽然所有参数都是从数据库传递的,但它会不断向我发送消息。

Anton: name of db table Anton:db表的名称

async def create_reply_activity2(text) -> Activity:
    return Activity(
        type=ActivityTypes.message,
        channel_id=Anton.query.all()[0],
        conversation=Anton.query.all()[1],
        recipient=Anton.query.all()[3],
        from_property=Anton.query.all()[2],
        text=text,
        service_url=Anton.query.all()[4])

resp = await create_reply_activity2("yo.")
    await context.send_activity(resp)

What you want to do is send a proactive message . 您要做的是发送主动消息 Ordinarily, bots function by only sending a message to a user when that user sends a message to the bot in what's called a turn. 通常,当用户在所谓的转弯中向机器人发送消息时,机器人仅通过向用户发送消息来起作用。 Since you want to send a message to a user outside of a turn in response to something other than that user messaging the bot, the message is considered proactive. 由于您希望在转弯之外向用户发送消息以响应该用户向机器人发送消息之外的其他内容,因此该消息被认为是主动的。 Therefore, you shouldn't be trying to send a message using the turn context because that context applies to the turn that's between the bot and the user who messaged it. 因此,您不应该尝试使用转向上下文发送消息,因为该上下文适用于机器人和发送消息的用户之间的转弯。

Instead of sending a message like this: 而不是发送这样的消息:

await context.send_activity(resp)

You should be sending a message like this: 您应该发送这样的消息:

credentials = MicrosoftAppCredentials(APP_ID, APP_PASSWORD)
connector = ConnectorClient(credentials, base_url=context.activity.service_url)
connector.conversations.send_to_conversation(Anton.query.all()[1].id, resp)

Of course, you should be storing the result of the query so you don't have to be running the same query over and over again. 当然,您应该存储查询的结果,这样您就不必一遍又一遍地运行相同的查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从机器人向另一个用户发送消息 - How to send message to another user from bot python 使用 Microsoft 团队机器人发送 pdf 文件 - python send pdf file with Microsoft teams bot 使用适用于 Python 的 Bot Framework SDK v4 初始化并向 Microsoft Teams 频道发送消息 - Initial and send a message to a Microsoft Teams channel using Bot Framework SDK v4 for Python 从 Viber bot 向订阅用户发送消息 - Send message from Viber bot to subscribed user 无法从我的不和谐机器人向用户发送私人消息? - Can't send private messages from my discord bot to user? 我试图让我的 discord 机器人等待用户在执行原始命令后发送另一条消息 - I'm trying to get my discord bot to wait for the user to send another message after they did the original command 我正在尝试让用户回复机器人响应,然后发送另一条消息 - I'm trying to make a user reply to a bot response then send another message 如何让我的 Discord Bot 使用他们的用户 ID 向另一个用户发送私人消息,我尝试了以下操作,但没有成功 - How Do I get my Discord Bot to Send a private message to another user using their user ID,I tried the following but it did not work 如何向执行 discord 机器人命令的用户发送直接消息? - How can i send a direct message to a user that executed a command to my discord bot? 如何让我的 Discord Bot 在每次用户输入“验证”时发送一条消息 - How can I make my Discord Bot send a message every-time a user types 'verify'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM