如何为python sdk的Bot框架格式化输出消息?

问题描述 投票:1回答:1

我正在尝试将自定义功能的输出用作聊天机器人输出的消息。我正在使用此链接提供的示例cookiecutter echo模板。

可以使用哪些方法来格式化聊天中可见的输出。例如粗体,斜体等。还有如何使用不同的格式。如将来一样,my_foo的out输出将是json。

Echo Bot Python sdk template

自定义功能

def my_foo(text):
     return text.upper()

Bot Function

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!")

如果有文档阐明此步骤或可以参考的一些基本步骤将是完美的。

python botframework chatbot markup microsoft-teams
1个回答
0
投票

关于在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)

Teams

© www.soinside.com 2019 - 2024. All rights reserved.