I am trying to use an output from custom function as a message for my chatbot output. I am using the sample cookiecutter echo template provided at this link.
What are the methods available to format the output that is visible in the chat. Such as Bold, Italic etc. And also how can i use different formats. As in future the out output of my_foo will be json.
Custom Function
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!")
If there is a documentation clarifying this or some basic steps that can be referred to that will be perfect.
All the information you need about formatting messages in Teams is right here. You use either Markdown or XML. I'm showing you how to set the optional text_format property of the activities, but Teams is smart enough to infer the format even if you don't set that property.
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)