How to use Twilio to send customized PDF’s from Google Drive/Sheets - node.js

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

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

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

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.

Sending existing messages with the gmail API

I'm trying to write a script that uses the gmail API to forward messages from my inbox to new recipients.
This guide recommends sending the base64 encoded string for the e-mail. Presumably, I could get the existing e-mail using the get method with format=raw, edit the base64 encoding to change the recipients, and send the new message along.
The messages I'm sending are quite large (many attachments), so this process (of downloading a massive base64 string, decoding it, doing some regex substituion, re-encoding it, and then re-uploading it) will take a long time. It also seems very cumbersome to use regex to manipulate a MIME email message.
It seems that there should be an easier way...? Perhaps some way to do this directly via the API?
Try to use the MailApp.sendEmail(). You can use that script to send to multiple receivers so sending messagees to many people wont be that cumbersome.
// Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file.
var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html');
MailApp.sendEmail('a#example.com,b#example.com,c#example.com', 'Attachment example', 'Two files are attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF), blob]
});
If you want additional samples, try this SO thread.

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