[英]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.