Docusign create envelope and apply template to newly added document Laravel 5.5 - laravel-5.3

Below is how i am sending doc for sign i need to run AutoPlace on this attached doc but iam not able to make it work. This code is working but not placing autoplace that i had set in this template.
$client = new DocuSign\Rest\Client([
'username' => config("docusign.DOCUSIGN_USERNAME"),
'password' => config("docusign.DOCUSIGN_PASSWORD"),
'integrator_key' => config("docusign.DOCUSIGN_INTEGRATOR_KEY"),
]);
$templateRole = $client->templateRole([
'email' => <email>,
'name' => <name>,
'role_name' => 'Client',
]);
$envelopeDefinition = $client->envelopeDefinition([
'status' => 'sent',
'email_subject' => 'Signature Required On Your Order ',
'template_id' => '<docusign template id>',
'template_roles' => [
$templateRole,
],
]);
$doc = Storage::disk('local')->url('mypdf.pdf');
$envelopeOptions = $client->envelopes->createEnvelopeOptions([
'documents' => [
'documentBase64' => base64_encode($doc),
'name' => 'mypdf.pdf',
],
]);
$envelopeSummary = $client->envelopes->createEnvelope($envelopeDefinition, $envelopeOptions);
print_R($envelopeSummary);
die();
Can you please suggest me how can i add that code.. Thanks in advance.

You are using wrong code pattern. With your code you can either apply template or you can add document to the envelope but you will not be able to apply template to the document. To apply a template to the document, you need to use Composite Template. If you have anchor strings (autoplace) present in both the server template and the added document then with composite template you will replace the server template document with the added document. An example would be like below. Server Template - 1afc0348-e853-4a0c-92db-06101168eb4d has a document with the anchorstring (autoplace), and FileName - "Added Document Agreement" in the "document" node has new document on which autoplace anchor string needs to be applied from the server template. Below code will show how to achieve this using composite template.
{
"compositeTemplates": [
{
"document": {
"documentBase64": "<Base64>",
"documentId": "1",
"fileExtension": "pdf",
"name": "Added Document Agreement"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"email": "email#gmail.com",
"name": "John Doe",
"recipientId": "1",
"roleName": "InternalSigner",
"routingOrder": "1"
}
]
},
"sequence": "2"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "1afc0348-e853-4a0c-92db-06101168eb4d"
}
]
}
],
"status": "sent"
}

Related

Google Calender API - Get eventID In a Calender

I need to get eventID's of a Calendar. I list events and some information about them but i can not get their ID's. I used this doc: https://developers.google.com/calendar/api/v3/reference/events/list
// Print the next 10 events on the user's calendar.
$calendarId = 'xxxx#group.calendar.google.com';
$optParams = array(
'maxResults' => 100,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => date('c', strtotime("monday -1 week")),
'timeMax' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
$events = $results->getItems();
if (empty($events)) {
print "No upcoming events found.\n";
} else {
//print "Upcoming events:\n";
foreach ($events as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s %s\n", $event->getSummary(), $start);
}
}
}
The method events.list
Returns a response
{
"kind": "calendar#events",
"etag": etag,
"summary": string,
"description": string,
"updated": datetime,
"timeZone": string,
"accessRole": string,
"defaultReminders": [
{
"method": string,
"minutes": integer
}
],
"nextPageToken": string,
"nextSyncToken": string,
"items": [
events Resource
]
}
Which contains a list of Event Resources
An event resource has a field called id.
{
"kind": "calendar#event",
"etag": etag,
"id": string,
....
So depending upon which language you would be using it would just be a matter of looping though each of the items returned by the method and then accessing the id of that event.
C# example.
foreach(var event in response.Items){
Console.WriteLine(event.Id)
}

Why does jsonfn.expand include null values?

I'm building up an array of JSON objects using jsonfn and rendering them on the JavaScript window object.
[#assign json = []]
[#list articles as article]
[#assign json += [jsonfn.from(article).add("categories", "title", "#name").expand("categories").inline().print()]]
[/#list]
<script>
window.articles = [${json?join(",")}];
</script>
While effective, the expanded categories field (expand("categories")) sometimes includes null values.
{
"categories": [
{
"displayName": "Example Category",
"#name": "example-category"
},
null
],
"title": "Example Article",
"#name": "example-article"
}
This requires me to add an instanceof Object check when filtering in JavaScript so that I don't get a null error.
export const filterArticles = (selectedCategory, articles) => {
return articles.filter((article) => {
return article.categories.find((category) =>
category instanceof Object && category['#name'] === selectedCategory
);
});
};
Why does jsonfn.expand sometimes output null values? Why isn't there a null safety check to avoid including them in the rendered output?
See JSONFN-5 ticket. Should be working without printing nulls as of version 1.0.9(-SNAPSHOT). Alternatively, pull the latest code from github and build it yourself.

How to get data from inline keyboard as single result?

I have a telegram bot that is set up and connected to my backend. When users choose the "enter password" option I send an inline keyboard next to the request so that the user can enter his numeric password. I do this so that the password will not be shown in the chat. The problem I have is that I make use of the callback_data to assign a value to the pressed button, but these callbacks come through one by one as the button is pressed. I would like to know is it possible to build up an accumulative string of pressed characters, and once the "Submit" button is pressed send through the user's response.
My Inline Request Currently looks as follow:
{
"chat_id": 99999999,
"text": "Enter Password",
"reply_markup": {
"inline_keyboard": [
[{"text": "1","callback_data":"1","pay":true},{"text": "2","callback_data":"2"},{"text": "3","callback_data":"3"}],
[{"text": "4","callback_data":"4"},{"text": "5","callback_data":"5"},{"text": "6","callback_data":"6"}],
[{"text": "7","callback_data":"7"},{"text": "8","callback_data":"8"},{"text": "9","callback_data":"9"}],
[{"text": "0","callback_data":"0"}],
[{"text": "Submit","callback_data":"Submit"}]
]
}
}
Further more is it possible to make the inline buttons go away after the submit has been pressed, I have gone through the telegram bot documentation, and can find any option like this.
https://core.telegram.org/bots/api#sendmessage
Kindly advise if this is possible or if I should take another approach.
Based on your comment, a simplified version of a KeyPad using php;
Note:
There should be more error checking (of course...)
The little 'clocks' on the pressed button can be removed by letting Telegram know you've seen the message. (Please see there docs)
<?php
$myChatId = 1234567;
$token = '859.....';
// Send keypad
$data = http_build_query([
'text' => 'Please enter pin;',
'chat_id' => $myChatId
]);
$keyboard = json_encode([
"inline_keyboard" => [
[
[ "text" => "1", "callback_data" => "1" ],
[ "text" => "2", "callback_data" => "2" ],
[ "text" => "3", "callback_data" => "3" ]
],
[
[ "text" => "4", "callback_data" => "4" ],
[ "text" => "5", "callback_data" => "5" ],
[ "text" => "6", "callback_data" => "6" ]
],
[
[ "text" => "7", "callback_data" => "7" ],
[ "text" => "8", "callback_data" => "8" ],
[ "text" => "9", "callback_data" => "9" ]
],
[
[ "text" => "<", "callback_data" => "<" ],
[ "text" => "0", "callback_data" => "0" ],
[ "text" => "OK", "callback_data" => "ok" ]
]
]
]);
$res = #file_get_contents("https://api.telegram.org/bot$token/sendMessage?{$data}&reply_markup={$keyboard}");
// Get message_id to alter later
$message_id = json_decode($res)->result->message_id;
// Remember pressId, so we wont add the same input
$last_presesd_id = 0;
// Continually check for a 'press', until we've reached 'ok' callback
// TODO; max 30sec - 4inputs
$pincode = [];
while (true) {
// Call /getUpdates
$updates = #file_get_contents("https://api.telegram.org/bot$token/getUpdates");
$updates = json_decode($updates);
// Check if we've got a button press
if (count($updates->result) > 0 && isset(end($updates->result)->callback_query->data)) {
// And this is the first time
if ($last_presesd_id === end($updates->result)->callback_query->id) {
continue;
}
// Get callback data (pressed number)
$callBackData = end($updates->result)->callback_query->data;
// Remember $last_presesd_id
$last_presesd_id = end($updates->result)->callback_query->id;
// Handle data
switch ($callBackData) {
// Stop, remove keyboard, show result
case 'ok':
// Show pincode and remove keyboard
$data = http_build_query([
'text' => 'Pincode: ' . implode('-', $pincode),
'chat_id' => $myChatId,
'message_id' => $message_id
]);
$alter_res = #file_get_contents("https://api.telegram.org/bot$token/editMessageText?{$data}");
// End while
break 2;
// <, remove last from pin input
case '<': {
array_pop($pincode);
break;
}
// 1, 2, 3, ...
default:
// Add to pincode
$pincode[] = $callBackData;
break;
}
}
// Sleep for a second, and check again
sleep(1);
}
I'm using editMessageText() to alter the message, to remove the keyboard. You could also us ReplyKeyboardRemove()

Processing custom NGINX log with logstash

I have nginx access log that log request body in the form of json string. eg.
"{\x0A\x22userId\x22 : \x22MyUserID\x22,\x0A\x22title\x22 : \x22\MyTitle\x0A}"
My objective is to store those 2 values (userId and title) into 2 separate fields in Elastic Search.
My Logstash config:
filter {
if [type] == "nginxlog" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG} %{QS:partner_id} %{NUMBER:req_time} %{NUMBER:res_time} %{GREEDYDATA:extra_fields}" }
add_field => [ "received_at", "%{#timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
mutate {
gsub => [
"extra_fields", x22 ,'"' ,
"extra_fields",x0A ,'\n'
]
}
json{
source => "extra_fields"
target => "extra_json"
}
mutate {
add_field => {
"userId => "%{[extra_json][userId]}"
"title"=> "%{[extra_json][title]}"
}
}
}
}
But it's not properly extracted, the value in ES userId = userId, instead of MyUserID. Any clue where is the problem? Or any better idea to achieve the same?

Symfony add Avatar field to sfGuardUser model

I have a project in symfony that I would like to let my users upload an image for their "avatar" field. I have found many posts about how to "extend" the table which I have with the schema below:
Member:
inheritance:
type: column_aggregation
extends: sfGuardUser
columns:
idmember: { type: integer }
birthday: { type: date }
avatar: { type: string(255) }
bio: { type: string(255) }
The columns get added to the table just fine, but when I go to change the widget to a sfWidgetFormInputFileEditable it breaks. Here is the Form.class file:
$file_src = $this->getObject()->getAvatar();
if ($file_src == '')
{
$file_src = 'default_image.png';
}
$this->widgetSchema['avatar'] = new sfWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/avatar/'.$file_src,
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
and "save" function of the form:
if($this->isModified())
{
$uploadDir = sfConfig::get('sf_upload_dir');
$thumbnail = new sfThumbnail(150, 150);
$thumbnail2 = new sfThumbnail(800, 800);
if($this->getAvatar())
{
$thumbnail->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
$thumbnail->save($uploadDir.'/avatar/thumbnail/'. $this->getAvatar());
$thumbnail2->loadFile($uploadDir.'/avatar/'.$this->getAvatar());
$thumbnail2->save($uploadDir.'/avatar/big/'. $this->getAvatar());
}
}
When I submit the form, I get this error message:
This form is multipart, which means you need to supply a files array as the bind() method second argument.
In the action where you bind the form you should use something like this:
$form->bind($request->getParamater($form->getName()), $request->getFiles($form->getName()));
So you need to pass the uploaded files as the second parameter to the bind method.

Resources