Unable to send pdf file from bot to user in ms teams - node.js

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.

Related

Add sample image in template header in whatsapp cloud API

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).
header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.
The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

How to use Twilio to send customized PDF’s from Google Drive/Sheets

I am having problems trying to send customized PDFs from Google Drive to users on WhatsApp using Twilio’s API.
I am using node.js and the documents are created in Google Sheets and stored in Google Drive.
client.messages
.create({
mediaUrl:['https://drive.google.com/uc?id=INSERT_FILE_ID&export=download'],
from: 'whatsapp:+14155238886',
body: `It's taco time!`,
to: 'whatsapp:+15017122661'
})
.then(message => console.log(message.sid));
I thought it would be possible to send the PDF by passing the PDF’s Drive link through MediaURL as that is what is recommended on Twilio’s site for sending media (Images, .mp3’s and PDF’s) but when I try that it doesn’t work.
NB: it works when I try image URL’s etc.
I have tried sending the webContentLink of the PDF that also doesn’t work.
example: how the pdf should look when sent
I do not want to send the user a normal link for them to leave WhatsApp.
Any help with this or any other method to achieve this would be greatly appreciated.
Twilio will check the content-type of the file which you have been passing in the mediaUrl parameter. Twilio will reject if the content-type headers of your media attachment do not match the file extension (for example, content-type is image/jpg but the file extension is .png). It specified in the following links specifies:
Twilio Troubleshooting
Twilio supported-mime-types

Google Drive UI Integration Issue: "Open with ..." suggestion is missing for my app's files

I recently launched a Marketplace app with a Google Drive UI Integration.
And I'm experiencing an issue where Google Drive fails to give users, who don't have my application installed in their Drive, a suggestion to "Open with ..." when previewing our third-party shortcut file.
A file's mimeType is used by Drive to make suggestions for applications compatible with the mimeType. Therefore it seems that Google Drive is unable to connect the mimeType that I am setting on my app's files to the mimeType in it's internal records.
The mimeType I set on my app's files is application/vnd.google-apps.drive-sdk (third party shortcut file) as instructed by docs [1]. Upon inspecting the html of the page, we see that Drive does in fact have the correct mimeType
<span class="a-q-Jc-wg" data-tooltip="application/vnd.google-apps.drive-sdk.6964198....." aria-label="application/vnd.google-apps.drive-sdk.6964198....." data-tooltip-align="b,c" data-tooltip-delay="500" data-tooltip-unhoverable="true">my app</span>
Those numbers (6964198.....) appended at the end make up my Google Cloud Project Id. Upon inspecting another marketplace app, Lucidchart, their mimeType is application/vnd.google-apps.drive-sdk.7081045131. If someone shares a Lucidchart shortcut with another person that does not have lucidchart installed, upon opening, they get the "Open with Lucidchart suggestion" Their app is working as expected, my isn't, and comparing the third-party shortcut file properties shows no difference.
Looking at one of our file's properties via "Get Details" in Drive shows that Google Drive is able to recognize the fileType as my app's file.
Once the user does install my application, they are able to see "Open with..." upon previewing the file. This gives the impression that mimeType is set correctly and available to drive, but GDrive is not properly using it before installation.
I have spent quite a lot of time trying to figure out what could be causing this issue, but I am stuck. I triple checked my configuration and everything seems to be set up correctly as directed by the docs [2].
I have 2 tickets opened to Google support on this matter, I even got on a call with them, but eventually they said that it seems like I'm doing everything correctly, but they can't help me any further and suggested to post a question on StackOverflow... So I'm asking for your help here.
My app's backend is written in Node.js and uses googleapis:51.0.0 module.
Here is a piece of my code that saves a file:
const gDrivePayload = {
requestBody: {
name: presentation.name,
mimeType: "application/vnd.google-apps.drive-sdk",
parents: [folderId],
properties: { presentationId }
}
};
if (thumbnailData) {
gDrivePayload.requestBody.contentHints = { thumbnail: { image: thumbnailData } };
}
const drive = google.drive({ version: "v3", auth: gAuthClient });
const gDriveResp = await drive.files.create(gDrivePayload);
gAuthClient is an instance of google.auth.OAuth2 with provided user tokens that were obtained via an oauth2 flow that was performed by the user.
thumbnailData is a base64 encoded jpeg image.
[1] https://developers.google.com/drive/api/v3/third-party-shortcuts
[2] https://developers.google.com/drive/api/v3/enable-sdk?hl=sk

Docusign - api get utl to download document

I need api to create URL link for download document of envelope.
I found this api:
GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}
But this api just return the file and i what a URL i can download the file (of course with expired time)
The endpoint you're looking for is:
POST /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}/views/recipient
You will need to provide in the body information about the recipient, see here for details:
https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeViews/createRecipient
We also have code examples in various langagues to show you how to do this here:
https://developers.docusign.com/esign-rest-api/code-examples/code-example-request-a-signature-via-email

File not supported error while uploading profile image file to IBM Connections using REST API

I'm trying to upload a jpeg file for profile image using the Profiles REST API to IBM Connections_v5.0. I however get an error message "The type of the photo file you provided is not supported".
I'm however able to upload the same file directly using the Connections UI interface directly. I'm setting the MIME type correctly as "image/jpeg".
Also tried with GIF and PNG images but get the same error message.
Any pointers would be very helpful.
I'm just using FF restclient addon to fire a REST call. So basically doing a PUT on /profiles/photo.do?key=....
Content-Type is set as "image/jpeg" and the payload consists of the image data in binary (base 64) encoded.
The payload should just be the binary of the image, there is no need to Base64 encode it.
You should refer to Adding a Profile Photo
You need to use a Key (great stackoverflow post here)
If you know the key for a user's profile you can do the following:
key — This is generated by Connections itself during the population
process. It is used to define the users profile within the context of
Profiles and provides Connections with the ability to associate
content with a user when the users LDAP information has been altered.
It provides a separation of identity and helps facilitate user content
synchronization for Connections.
Once you have a key, you make the following request
URL: https://profiles.enterprise.example.com/profiles/photo.do?key=
b559403a-9r32-2c81-c99w-ppq8bb69442
METHOD: PUT
CONTENT-TYPE: image/png
input the binary content on the stream
you should be able to use "image/jpeg", "image/jpg", "image/png" or "image/gif"
If you have an error after the PUT method, you should add the SystemOut.log lines which are relevant.

Resources