MS Teams Bot - 从短信中删除所有@mentions
MS Teams Bot - remove all @mentions from text message
我正在使用 MS Teams Bot Framework 编写一个交互式聊天机器人,我正在尝试从聊天消息中删除所有提及的内容。 IE。
我正在写给机器人的消息(在团队频道内,@general 提到推送通知):
"@general @bot hello world" 我的代码只需要没有任何提及的短信 -> "hello world".
我的代码:
async def on_message_activity(self, turn_context: TurnContext):
user = turn_context.activity.from_property.name
turn_context.remove_recipient_mention(turn_context.activity)
user_input = turn_context.activity.text.strip()
我希望“turn_context.remove_recipient_mention(turn_context.activity)”能够处理它并从短信中删除收件人。
如果我只提到@bot,它会起作用,但当我在消息中多次提到它时,它就不起作用。
如何删除聊天消息中的所有提及?
你可以看上面的方法一,在你发送的link上,是“remove_mention_text”。每次提及都需要一个 ID,但是如果您查看代码 (here),它基本上会访问 TurnContext.get_mentions(activity)
,因此您实际上可以创建自己的方法,例如 remove_all_mentions
而不是编写自定义 remove_all_mentions 调用 TurnContext.get_mentions(activity)
并且每次提及调用 TurnContext.remove_mention_text(turn_context.activity,mention_id)
async def on_message_activity(self, turn_context: TurnContext):
user = turn_context.activity.from_property.name
mentions = turn_context.get_mentions(turn_context.activity)
if mentions:
for mention in mentions:
mention_id = mention.additional_properties["mentioned"]["id"]
turn_context.remove_mention_text(turn_context.activity,mention_id)
我正在使用 MS Teams Bot Framework 编写一个交互式聊天机器人,我正在尝试从聊天消息中删除所有提及的内容。 IE。 我正在写给机器人的消息(在团队频道内,@general 提到推送通知):
"@general @bot hello world" 我的代码只需要没有任何提及的短信 -> "hello world".
我的代码:
async def on_message_activity(self, turn_context: TurnContext):
user = turn_context.activity.from_property.name
turn_context.remove_recipient_mention(turn_context.activity)
user_input = turn_context.activity.text.strip()
我希望“turn_context.remove_recipient_mention(turn_context.activity)”能够处理它并从短信中删除收件人。
如果我只提到@bot,它会起作用,但当我在消息中多次提到它时,它就不起作用。
如何删除聊天消息中的所有提及?
你可以看上面的方法一,在你发送的link上,是“remove_mention_text”。每次提及都需要一个 ID,但是如果您查看代码 (here),它基本上会访问 TurnContext.get_mentions(activity)
,因此您实际上可以创建自己的方法,例如 remove_all_mentions
而不是编写自定义 remove_all_mentions 调用 TurnContext.get_mentions(activity)
并且每次提及调用 TurnContext.remove_mention_text(turn_context.activity,mention_id)
async def on_message_activity(self, turn_context: TurnContext):
user = turn_context.activity.from_property.name
mentions = turn_context.get_mentions(turn_context.activity)
if mentions:
for mention in mentions:
mention_id = mention.additional_properties["mentioned"]["id"]
turn_context.remove_mention_text(turn_context.activity,mention_id)