How to send a file attached to the signature request email - php

I'm using the PHP SDK to integrate DocuSign eSign REST API into a Laravel application.
We have been asked to attach a couple of PDF files to every signature request email, but I don't know if this is even possible.
I thought that the EnvelopeAttachments resource would be a way to go, but signers do not receive any attachment so far and here it is said that such attachments are not visible for them.
Here there is the SDK code I am using:
$attachments = [
new Attachment([
'access_control' => 'sender',
'attachment_id' => '1',
'attachment_type' => '.pdf',
'data' => base64_encode($this->getPdf($document, $signers)),
'label' => 'attachment 1',
'name' => 'attachment 1',
'remote_url' => 'attachment 1',
]),
];
$envelope_definition = new EnvelopeDefinition([
'composite_templates' => $composite_templates,
'email_subject' => "Firmar $documentTypeSp",
// 'email_blurb' => "Se solicita su firma para el contrato $document->name",
'status' => "sent",
'attachments' => $attachments,
]);
$envelope_definition->setEnvelopeAttachments($attachments);
return $envelope_definition;

You cannot attach a file to this email that is auto-generated by the system.
The envelope attachment shows in the envelope, it is not attached to the email.
While I don't recommend it, your only option is to send emails yourself, with links going to your own webserver, where you generate embedded signing URLs on the fly and redirect the users.
I would suggest you consider an alternative to having the attachment in the email. Like having a link in the email that goes to some sort of cloud storage or to your own server.

The EnvelopeAttachments resource is used to attach a document to an envelope. According to the API documentation, attachments are not visible to signers. So, it appears that it is not possible to attach a file to the signature request email.
One alternative approach to include the PDF files in the email body is to embed them as inline images. You can convert the PDF to an image format, such as PNG or JPG, and then embed the image into the HTML email body using the <img> tag. The recipient can then view the PDF document directly in the email.

Related

How to send Push with different data for each token in Firebase?

There is such a code, but it sends a single message to all the tokens specified in the array (1000 tokens). You need to add a personal parameter for each token somewhere to track the unique click - from whom it comes and so on. For example, in click_action. But again, if you add a parameter there, the link in this form will be sent to everyone. Sending one message for each user is not an option, of course.
'registration_ids' => $tokens,
'data' => array(
'title' => 'Title',
'body' => 'Message',
'icon' => 'icon.png',
'image' => 'image.png',
'click_action' => 'https://site.ru'
);
There is no (mail merge like) customization for each recipient within a single API call. Each call to the FCM API to send a message, sends precisely the message you pass in that call to the topics/tokens you target in that call.
If you want recipients to receive a different message, you will need to perform one API call for each message.
You say:
Sending one message for each user is not an option
Calling the API fo each unique message is precisely the only option. I'm not sure why it wouldn't be, as it's what all apps using FCM do if they want to deliver personalized content.

How to create a Slack message containing an uploaded image?

I'd like to create a message in the #general channel of my Slackspace from within a PHP script. The message should contain text and an image which was created locally on-the-fly.
I've already created an App, generated an bearer token and have managed to create an text-only message also as an image-upload.
But i didn't know how to create both in one message, as the procedure above creates two messages, one with text and another one with the image.
There are two different approaches on how to post a Slack message with an image.
A. Upload image directly with message
You can upload an image directly to Slack and share it in a channel. Within that request you can also add a comment that will appear as message above the images. This is the easiest approach, however you comment is limited to one string.
API method: files.upload with these arguments:
channels: ID of one or multiple channel for the image to appear in
initial_comment: Your message
B. Post message with image block / attachment
Alternatively you can add an image to your normal message either as image block or secondary attachment. This only works with a public URL to your image file, so you first need to upload your image to an image hoster (which can be your Slack workspace) to get the public URL.
In our example we will use Slack as image hoster, but you can use any image hoster (e.g. Imgur) even your own webserver, as long as you get a public URL for your image file.
Step 1 - Upload image to Slack
API method: files.upload with no special arguments, but make sure to get the file ID from the response. Don't include the channels argument or the image will be posted visible into those channel.
Step 2 - Create public URL
Next you have to mark the uploaded file as public. Only then will it be accessible through its public_url property
API method: files.sharedPublicURL with the file ID as argument.
Next you need to construct the direct image link from the link to website / permalink_public property of the file.
The website link you get from permalink_public has the format:
https://slack-files.com/{team_id}-{file_id}-{pub_secret}
The direct link to the image has the format:
https://files.slack.com/files-pri/{team_id}-{file_id}/{filename}?pub_secret={pub_secret}
So you just need to extract the pub_secret from permalink_public and you should be able to construct the direct link to the image. The other parameters you can get from your file object.
Step 3 - Send message
Finally compose your message with the image URL either as Image Block or in a secondary attachment and submit it using a method of your choice.
API method: chat.PostMessage or any other method for sending message incl. incoming webhooks.
Answer to OP
If you need to stick with webhooks as it appears from your comments and have no access to the Slack API I would suggest uploading the image to an image hoster (e.g. Imgur) and then use approach B.
See also
Slack bot send an image
Can I upload an image as attachment with Slack API?
How to use the permalink_public URL of an uploaded image to include it in a message?
After much tinkering I found that while I could not use the API to create a message and upload an image simultaneously, I can first upload an image and then, with the timestamp returned, use update message to add text to the original message with the image upload.
This is the flow:
1- Use files_upload method to upload an image to my channel (using the channel name)
response = client.files_upload(
channels=my_channel_name,
file=image_path,
initial_comment='My initial comment'
)
2- Get the response from the files_upload and extract the channel id and timestamp of the message.
channel_id = response['file']['groups'][0]
ts = response['file']['shares']['private'][channel_id][0]['ts']
3- Use chat update to add text or rich content to the message with the uploaded image:
response = client.chat_update(
channel=channel_id,
text="My Message",
ts=ts,
blocks=blocks_list
)
For those who might still need this.. this gist helped me. Its a quick and easier way using GuzzleHttp.
use GuzzleHttp\Client;
/**
* Notes:
*
* Tested with guzzlehttp/guzzle version 7.3
* See https://api.slack.com/methods/files.upload for details on how to generate a token
*
*/
$fileName = '';
$filePath = '';
$slacktoken = ''; // See https://api.slack.com/tokens; The token will need file.read and file.write permissions
$client = new Client();
$apiUrl = 'https://slack.com/api/files.upload';
$client = new Client();
$request = $client->post( $apiUrl, [
'headers' => ['Authorization' => 'auth_trusted_header'],
'multipart' => [
[
'name' => 'token',
'contents' => $slacktoken,
],
[
'name' => 'file',
'contents' => fopen($filePath, 'r'),
'filename' => $fileName
],
[
'name' => 'channels',
'contents' => '#general'
],
[
'name' => 'initial_comment',
'contents' => 'File Uploaded'
]
]
]);
var_dump($request->getBody()->getContents());

How to send batch/mass emails with attachments using mailgun?

I want to send batch emails with attachment. I can send the batch emails by attaching the same file to all the emails. But I need to attach different files to different emails by adding file path in recipient variables. I can't see anything related in the official documentation of mailgun.
Here is my code :
# Instantiate the client.
$mgClient = new Mailgun('key-****');
$domain = "foo.bar.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'gido#foo.baar.com',
'to' => array('user1#gmail.com', 'user2#gmail.com'),
'subject' => 'Hi %recipient.first%',
'text' => 'Hey there, Just Testing',
'recipient-variables' => '{"user1#gmail.com": {"first":"User1", "id":1, "file" : "/path/to/file1"},
"user2#gmail.com": {"first":"User2", "id": 2, "file" : "/path/to/file2"}}'
), array(
'attachment' => array('%recipient.file%')
));
The above code does not work. the attachment array is not able to use recipient variable. Replacing %recipient.image% with /path/to/file works fine.
As per conversation with the Mailgun support team, At this time Mailgun doesn't have a way to assign a specific attachment to each recipient. One thing that can be tried is serving the files on a server and assign the users a URL to retrieve the file from(This is suggested only in case if files are not confidential and stored permanently on the server.).
From the doc:
'attachment' => [['fileContent'=>$binaryFile,'filename'=>'test.jpg']]
OR
'attachment' => [['filePath'=>'/tmp/foo.jpg','filename'=>'test.jpg']]
OR (inline):
'inline' => [['filePath'=>'/tmp/foo.jpg', 'filename'=>'test.jpg']]

How i can send image in email with cakephp 3 email template?

I'm trying to send image into email,
My image code is: <?php echo $this->Html->image('image-name.jpg', ['class'=>'img-responsive']); ?>
While i'm debug email template in my localhost, it's working fine, image displaying properly, but when this same code make it live on server and fire email, email content display properly but image not showing(not found).
Any body will suggest proper way to implement it.
Thanks,
Mak
For the email or in whole website if you want to full path of content use fullBase param with true value,
echo $this->Html->image("logo.png", ['fullBase' => true]);
Will output:
<img src="http://example.com/img/logo.jpg" alt="" />
https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images
This is a proper way that suggested by CakePhp framework.
First attach the file what you want to send
$email->attachments([
'photo.png' => [
'file' => '/full/some_hash.png',
'mimetype' => 'image/png',
'contentId' => 'unique-id'
]
]);
And then in your email template, add the unique id
<img src="cid:unique-id">
Detail explanation, here

ALL GCM parameters?

i´ve written a "pushserver" for my app via PHP.
The push notifications i´ve sent via PHP are all received on the device, so far.
But, i can just send/set the "message" and "title", see:
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array(
'message' => $message,
'title' => 'My App',
'vibrate' => 1,
'sound' => 1,
'icon' => "http://example.com/image.jpg",
"style" => "inbox"
),
);
"icon" and "style" are not working (vibrate and sound not tested, yet).
Every link for the parameters i´ve found is broken or kind of "you need to do object.setSomething() in JAVA.
Is there a list anywhere where i can see ALL parameters, which i can send to GCM? No matter, what language i use?
Cheers,
Chris
couple of things need to keep in mind while all the data which you sending from server end
Is there a list anywhere where i can see ALL parameters,
exp :- you can send as many parameters as you want but offcourse there is limitation but not key specific just like you can use "textmessage" instead of "message" but make sure to retrieve the value from same key which you are assigning from server end
1) please make sure that you are getting all the data in gcmintentservice class try to print the log of all intent data.
please remember that this is just a string data it is not going to download the image for you. you have to download using volley library or any suitable library

Categories