Attached PDF to MS Teams chatbot

Question:

I am trying to attach a pdf file in a MS Teams bot.

I get the following error " [on_turn_error] unhandled error: (BadArgument) Unknown attachment type". 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}",
            )        
Asked By: bitterjam

||

Answers: