[英]Attached PDF to MS Teams chatbot
I am trying to attach a pdf file in a MS Teams bot.我正在尝试在 MS Teams 机器人中附加一个 pdf 文件。
I get the following error " [on_turn_error] unhandled error: (BadArgument) Unknown attachment type".我收到以下错误“[on_turn_error] 未处理的错误:(BadArgument) 未知的附件类型”。 Would anyone know why it might not work?
有谁知道为什么它可能不起作用?
The following is a portion of my code that concerns the error... unfortunately since it is a chatbot it is not appropriate to put the full code here.以下是我的代码中与错误有关的部分...不幸的是,由于它是一个聊天机器人,因此不适合将完整代码放在这里。
Thank you for your advice.感谢您的建议。
class MyBot(ActivityHandler):
async def on_message_activity(self, turn_context: TurnContext):
elif str(turn_context.activity.text).upper() in {'PDF'}:
reply = Activity(type=ActivityTypes.message)
reply.text = "This is the pdf file."
reply.attachments = [self._get_inline_attachment()]
await turn_context.send_activity(reply)
#truncated#
def _get_inline_attachment(self) -> Attachment:
file_path = os.path.join(os.getcwd(), "TEST.pdf")
with open(file_path, "rb") as pdf_file:
dencoded_string = base64.b64encode(pdf_file.read()).decode()
return Attachment(
name="TEST.pdf",
content_type="application/pdf",
content_url=f"data:application/pdf;base64,{dencoded_string}",
)
@Nivedipa-MSFT indicated that the sample code for file sharing on MS Teams is avail here: https://github.com/microsoft/BotBuilder-Samples/blob/22fcff680a3e11006eb09b81ac5ed4de345933e2/archive/samples/python/56.teams-file-upload/bots/teams_file_bot.py @Nivedipa-MSFT 指出 MS Teams 上的文件共享示例代码在此处可用: https://github.com/microsoft/BotBuilder-Samples/blob/22fcff680a3e11006eb09b81ac5ed4de345933e2/archive/samples/python/56.teams-file-upload /bots/teams_file_bot.py
If I may add, "supportsFiles" has to be enabled in the manifest for this to work: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema#bots and https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-files#configure-your-bot-to-support-files如果我可以添加,“supportsFiles”必须在清单中启用才能工作: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema#bots和https: //learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bots-files#configure-your-bot-to-support-files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.