简体   繁体   中英

Unable to send pdf file from bot to user in ms teams

NodeJS BotBuilder SDK version: 3.15.0 My code:

var pdf = {
  name: '<file_name>.pdf',
  contentType: 'application/pdf',
  contentUrl: '<https url to public pdf file>'
};
var reply = new builder.Message(session).addAttachment(pdf);
session.send(reply);

This code is the same in few online examples. The issue I have is that I always get error:

Error: POST to 'https://smba.trafficmanager.net/emea/v3/conversations/a%3A1TwHmhoGuZP2Mf9P0TTnjv8HkcaXzEHryv0sYCvDDUI-qrMitJtHRlAnIcedcDH_v3IfMBXtg_zo5MDVcS0-8hDCQ4sJzpJhrewBPK8uWJXYeShgmd-s7uh5o8kW4ebAP/activities/1543588440246' failed: [400] Bad Request

For image/png this code works fine.

What I want to achieve is this: (image is taken from Bot Framework Emulator) File from the web sent from bot to user

The file is sent from bot without uploading it to users's one drive. This works also when I tested the feature in test section of https://dev.botframework.com/bots . It doesn't work only in ms teams.

The behaviour for sending files can differ per channel. Microsoft Teams doesn't support the direct upload method, like the WebChat / Emulator does. This is due to compliance reasons, as Bill Bliss stated .

You can post messages with card attachments referencing existing SharePoint files using the Microsoft Graph APIs for OneDrive and SharePoint. Using the Graph APIs requires obtaining access to a user's OneDrive folder (for personal and groupchat files) or the files in a team's channels (for channel files) through the standard OAuth2 authorization flow. This method works in all Teams contexts.

Have a look at Send and receive files through your bot for the full documentation and how to implement.


An alternative option would be to use an AdaptiveCard where you can use an image thumbnail of the document combined with a button to directly download the PDF file from your public accessible URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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