我正在尝试使用自定义函数的输出作为聊天机器人输出的消息。我正在使用此链接提供的示例 cookiecutter echo 模板。
有哪些方法可用于格式化聊天中可见的输出。例如粗体、斜体等。还有我如何使用不同的格式。将来 my_foo 的输出将是 json。
自定义函数
def my_foo(text):
return text.upper()
机器人功能
class MyBot(ActivityHandler):
# See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
async def on_message_activity(self, turn_context: TurnContext):
await turn_context.send_activity(f"Upper Case { my_foo(turn_context.activity.text }")
async def on_members_added_activity(
self,
members_added: ChannelAccount,
turn_context: TurnContext
):
for member_added in members_added:
if member_added.id != turn_context.activity.recipient.id:
await turn_context.send_activity("Hello and welcome!")
如果有一个文档澄清这一点或一些可以引用的基本步骤,那就完美了。
最佳答案
有关在 Teams 中设置消息格式所需的所有信息是 right here 。您可以使用 Markdown 或 XML。我将向您展示如何设置事件的可选 text_format 属性,但即使您不设置该属性,Teams 也足够智能来推断格式。
from botbuilder.schema import TextFormatTypes
. . .
async def on_message_activity(self, turn_context: TurnContext):
markdown_reply = MessageFactory.text(
f"Here is *italic* and **bold** with Markdown")
xml_reply = MessageFactory.text(
f"Here is <i>italic</i> and <b>bold</b> with XML")
# markdown_reply.text_format = TextFormatTypes.markdown
# xml_reply.text_format = TextFormatTypes.xml
await turn_context.send_activity(markdown_reply)
await turn_context.send_activity(xml_reply)
关于python - 如何格式化 python sdk 的 Bot 框架的输出消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58796075/