简体   繁体   English

附加 PDF 到 MS Teams 聊天机器人

[英]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}",
            )        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM