Constructing PHP Array for Hangouts Webhook - php

I'm trying to build the following Array with PHP so that I can send a card to Google Hangouts Chat Webhook.
{
"cards": [
{
"sections": [
{
"widgets": [
{
"keyValue": {
"topLabel": "Order No.",
"content": "12345",
"contentMultiline": "false",
"bottomLabel": "Delayed",
"onClick": {
"openLink": {
"url": ""
}
},
"icon": "TRAIN",
"button": {
"textButton": {
"text": "VISIT WEBSITE",
"onClick": {
"openLink": {
"url": ""
}
}
}
}
}
}
]
}
]
}
]
}
This is where I got to but does not seem to work..
$card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = "Issue No";
$card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = $_GET["issueid"];
$card["cards"]["sections"]["widgets"]["keyValue"]["contentMultiline"] = false;
Any help would be amazing, just a brief overview of how to contsruct the above array in PHP.
Thanks!

Solved.
$card["cards"]["sections"]["widgets"]["keyValue"]["topLabel"] = $_GET["issueid"];
this will overwrite above the one I think, I think ["topLabel"] should be ["content"] in the second index ??
Thanks #devpro

Related

PHP Select Data from Json

My JSON Data
{
"users": [
{
"userid": 1,
"username": "Admin",
"usermail": "admin#admin.com",
"authority": [
{
"authorityid": 1,
"authoritytext": "Admin",
"mission": [
{
"permission": "add"
},
{
"permission": "delete"
},
{
"permission": "move"
}
]
},
{
"authorityid": 1,
"authoritytext": "Super Admin",
"mission": [
{
"permission": "no add"
},
{
"permission": "no delete"
},
{
"permission": "only moderate"
}
]
}
]
}
]
}
MY PHP
foreach($result->users as $ok) {
foreach($ok->authority as $okey) {
foreach($okey->mission as $okeyokey) {
$test = $okeyokey->permission;
echo $test;
}
}
}
How to make this?
I want show parse json only authority{0} -> misson{0} show "permission" "add" please help me .
Maybe look ScreenShot >>>>>
I want filter {0}{1}{2} and select 0 -> show parse json
enter image description here
Is this what you are looking for?
<?php
$jsonData = '{
"users": [
{
"userid": 1,
"username": "Admin",
"usermail": "admin#admin.com",
"authority": [
{
"authorityid": 1,
"authoritytext": "Admin",
"mission": [
{
"permission": "add"
},
{
"permission": "delete"
},
{
"permission": "move"
}
]
},
{
"authorityid": 1,
"authoritytext": "Super Admin",
"mission": [
{
"permission": "no add"
},
{
"permission": "no delete"
},
{
"permission": "only moderate"
}
]
}
]
}
]
}';
$data = json_decode($jsonData);
echo($data->users[0]->authority[0]->mission[0]->permission);
You are getting objects and arrays confused
foreach($result->users as $currentUser){
$auths = $currentUser->authority;
foreach($auths as $currentAuth){
foreach($currentAuth->mission as $permission){
foreach($permission as $positionLabel => $permissionValue){
if($permissionValue == "add"){
// code here
}
}
}
}
}
Make sure you are using good labels. Dummy placeholders can be fine, but it makes tracking bugs really hard. I assume you want to check if they hold permission using a database, using PDO?
// array
$arr = ["this", "is", "an", "array"];
echo $arr[0] // prints out the word this.
$json = { "attribute": "value"}
echo $json->attribute // prints out the word value.
You can have arrays in JSON objects, and JSON Objects in arrays. How you access them are different.

Elastisearch Failed to JSON encode issue

I working on elastic search and I have 1K phone numbers when I pass this phone numbers array to elastic search to search users through phone numbers it gives me exception
Failed to JSON encode /var/app/current/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php
Below is my Elasticsearch client initializing
$client = ClientBuilder::create()->setHosts([$host])->build();
And my working query in Elasticsearch
{
"_source": [
"id"
],
"query": {
"bool": {
"must": [
{
"term": {
"type": "user"
}
},
{
"bool": {
"should": [
{
"prefix": {
"phone": {
"value": "923047698099"
}
}
},
{
"prefix": {
"phone": {
"value": "92313730320"
}
}
},
.
.
.
]
}
}
],
"must_not": [
{
"has_child": {
"type": "blocked",
"query": {
"term": {
"user_id": "u-2"
}
}
}
},
{
"has_child": {
"type": "block",
"query": {
"term": {
"user_id": "u-2"
}
}
}
},
{
"term": {
"db_id": 2
}
}
]
}
}
}
I don't know that where I doing mistake. Either at client initializing or writing elasticserch query. I searched this issue but not usefull solution found or might be I did't understand clearly. But still I am stucked on this issue that how to solve this problem. Suggest any usefull link or solution.
Thanks

[Dialogflow]Update Permission through Webhook format (for push notifications)

ORIGINAL REQUEST: I'm trying to implement the push notifications following the documentation: https://developers.google.com/actions/assistant/updates/notifications
I'm using Dialogflow with webhooks (in PHP) and the documentation is giving example in nodeJS
Right now, i'm blocked because of the Update permission, here's my Webhook response :
{
"source": "webhook",
"payload": {
"google": {
"expectUserResponse": true,
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
]
},
"updatePermission": {
"intent": "notification.simple.text"
}
}
}
}
}
When I do the simulation, asks me a permission for a push, but not for the intent I specified.
I'm quiet sure that the problem is the updatePermission, something must be wrong with that:
Is it the field name?
In intent, i put the intent name that i filled in dialogflow, maybe do i have to an use action? Is it in the good format ?
If someone can help me or just give me an example of a clean response for an update permission.
Thanks!
Solution
I just found why, my json wasn't good, the updatePermissionValueSpec must be into data object.
{
"source": "webhook",
"payload": {
"google": {
"expectUserResponse": true,
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
],
"updatePermissionValueSpec": {
"intent": "notification_simple_text"
}
}
}
}
}
}
I believe updatePermission should be named updatePermissionValueSpec.
Example response:
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"permissions": [
"UPDATE"
],
"updatePermissionValueSpec": {
"intent": "intent_name"
}
}
}
}
}

how to validate a json empty object in php

my php code works fine when it returns the result like this ->
{
"id": 267935,
"results": [
{
"key": "rc94yWXcyr0",
"name": "Trailer 1",
"site": "YouTube"
},
{
"key": "GZ0Bey4YUGI",
"name": "Official Trailer",
"site": "YouTube"
},
{
"key": "y1fZg0hhBX8",
"name": "Official Trailer 2",
"site": "YouTube"
}
]
}
but i get error
(Notice: Undefined variable: finaltrailers in ... )
when results return like this -->
{
"id": 392344,
"results": [
]
}
and this is my php code -->
$trailer = $json2['results'];
foreach($trailer as $trailers=>$keytrailers){
foreach($keytrailers as $alltrailers=>$allkeytrailers){
if($alltrailers == 'key'){
# $finaltrailers .= $allkeytrailers.',';
}
}
}
echo trim($finaltrailers,",");
how can i validate the empty array and give and error my self ? please help me thank you.
You have to define the variable to use it in trim.
Just add it at the beginning of your code.
$finaltrailers = '';
$trailer = $json2['results'];
foreach($trailer as $trailers=>$keytrailers){
foreach($keytrailers as $alltrailers=>$allkeytrailers){
if($alltrailers == 'key'){
# $finaltrailers .= $allkeytrailers.',';
}
}
}
echo trim($finaltrailers,",");

Trying to pre-fill text-tabs in Docusign via Rest API

I am having problems prefilling textTabs for my server templates in my docusign console. My application generates an agreement on our end and is added as a composite template along with another form that is added as a server template with a template id.
The server template has several fields the user needs to be able to fill out. The tabs have been defined and added with the manage template tool in the docusign console.
I have no problems sending the documents and the signHereTab is the only one that is correctly added to the form.
The two problems I have are 1) the fields the user should fill out are never shown on the recieved document, 2) the prefill information I am sending is not received by docusign. Below is the body request I am sending to the docusign REST API:
{
"emailSubject":"Nexogy Service Agreement Signature Request",
"emailBlurb":"Thank you for your interest in our services. Please sign the following agreement to continue with your service installation.",
"status":"sent",
"emailSettings":{
"replyEmailAddressOverride":"sales#nexogy.com",
"replyEmailNameOverride":"Nexogy",
"bccEmailAddresses":[
]
},
"eventNotification":{
"url":"https:\/\/dna.local.com\/documents\/set-status",
"loggingEnabled":true,
"requireAcknowledgment":true,
"useSoapInterface":false,
"includeDocuments":false,
"includeSenderAccountAsCustomField":true,
"envelopeEvents":[
{
"envelopeEventStatusCode":"Sent"
},
{
"envelopeEventStatusCode":"Delivered"
},
{
"envelopeEventStatusCode":"Signed"
},
{
"envelopeEventStatusCode":"Voided"
},
{
"envelopeEventStatusCode":"Declinded",
"includeDocuments":true
},
{
"envelopeEventStatusCode":"Completed",
"includeDocuments":true
}
]
},
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718
}
]
},
"compositeTemplates":[
{
"inlineTemplates":[
{
"sequence":1,
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"signHereTabs":[
{
"xPosition":100,
"yPosition":205,
"documentId":1,
"pageNumber":6,
"fontColor":"BrightBlue"
}
]
}
}
]
},
"documents":[
{
"documentId":1,
"name":"ChuyMPDFAgreement.pdf",
"remoteUrl":"https:\/\/s3.amazonaws.com\/dna_local\/ChuyMPDFAgreement.pdf"
}
]
}
]
},
{
"serverTemplates":[
{
"sequence":2,
"templateId":"ae435358-1410-40fd-803e-273028d19287",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"Full Name",
"value":"Test Tester",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"1"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
},
{
"tabLabel":"Country",
"value":"US",
"pageNumber":"1"
},
{
"tabLabel":"Phone",
"value":"3454657676",
"pageNumber":"1"
},
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":"\\*FullName",
"value":"Test Tester",
"pageNumber":"1"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":3,
"templateId":"017d0d20-754b-4093-8896-ff1c00ee2cda",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"1"
},
{
"tabLabel":123123123,
"value":123123123,
"pageNumber":"2"
}
]
}
}
]
}
}
]
},
{
"serverTemplates":[
{
"sequence":4,
"templateId":"11a88684-07ac-4ee5-9994-cb88635fb42f",
"recipients":{
"signers":[
{
"email":"mmoreno509#gmail.com",
"name":"Test Tester",
"roleName":"Signer1",
"recipientId":718,
"tabs":{
"textTabs":[
{
"tabLabel":"AccountName",
"value":"Testing Company",
"pageNumber":"2"
},
{
"tabLabel":"Address",
"value":"Test",
"pageNumber":"1"
},
{
"tabLabel":"City",
"value":"Hollywood",
"pageNumber":"1"
},
{
"tabLabel":"State",
"value":"FL",
"pageNumber":"1"
},
{
"tabLabel":"ZipCode",
"value":33081,
"pageNumber":"1"
}
]
}
}
]
}
}
]
}
]
}
You can not update template tabs upon creation of the envelope at this time.
Your signHereTabs is in your inlineTemplate, which will add additional tags to your envelope.
If you want to update tabs that are contained in a template via the API, your workflow should look like:
Create Envelope - ("status" : "created")
Modify Envelope - Edit tags here
Send Envelope
All of the documentation around building this workflow is located in DocuSign REST API Guide

Categories