Dialogflow Crash in AWS Deployment - php

I deployed the same source code to AWS EC2 Linux instance, but it fails to display the response Text from dialogflow.
I checked the conversation history in Dialogflow console, it shows both request and response correctly. However, the dialogflow client(PHP) seems crashes after calling the function "detectIntent".
Unfortunately, got no way to find any logs.
Reinstalled Dialogflow Client Library
$formattedSession = $sessionsClient->sessionName($agent, $agentSession->session_id);
// Set Text Input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($lang);
// Set Parameters
$optionalArgs = array();
$queryInput = new QueryInput();
$queryInput->setText($textInput);
$response = $sessionsClient->detectIntent($formattedSession, $queryInput, $optionalArgs);
$action = $response->getQueryResult()->getAction(); //The action name from the matched intent.

Hope the following experience helps others:
For my case, the php version is not compatible with one of the Google API library. Hence it crashes somewhere we cannot capture.
Solution: Uninstall PHP, and Install the compatible version of php.

Related

Cannot Verify Shopify Webhook

I have setup a webhook in shopify via settings > notifications > webhooks and entered a heroku app URL. My heroku app is in php and I run the verification function found here: https://shopify.dev/tutorials/manage-webhooks and when I open my app I get a blank response. I am not sure if this is something I am doing wrong on my heroku app, or if I am missing something. The goal here is to grab the json data after the event I have selected is ran, then to send that data to via third party api. But to start I just want to be able to verify that my heroku app is receiving the payload. Is there more I need to add to my php file in order to verify? (php noob here). Below is the code I am running in my php file, and yes I am using my shared secret found in the webhooks section.
<?php
define('SHOPIFY_APP_SECRET', 'my_shared_secret');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result
?>
If I am not mistaken you cannot test webhooks that way as the admin does not use your API key as it has no idea who you are when in the admin. So if you have a heroku App and it has an API key, use that API key to first off establish the webhook, verify you created it with the API, and then sit around and test your actual endpoint with Shopify Admin itself. That is how it works AFAIK.
The other verification in the admin is mickey mouse and meant to just throw data at any old endpoint with no validation.

Getting ms exchange server version using php-ews

I am using php-ews library(new version) to display the calendar events of the users in my project. The users can set their ms exchange account details in their profile and then use the calendar within my project itself. The code is like below
$host = '{host_set_on_users_profile}';
$username = '{username_set_on_users_profile}';
$password = '{password_set_on_users_profile}';
$version = Client::VERSION_2016;
$client = new Client($host, $username, $password, $version);
$client->setTimezone($timezone);
// Build request
$request = new FindItemType();
// more request building code here
$response = $client->FindItem($request);
But I am getting the below issue
[faultstring] => The specified server version is invalid.
The reason is I have used fixed VERSION_2016 and the users can have any version of ms exchange set up for the account.
So is there any way using which first I can find out the server version based on host,username and password? so that I can use the same for creating the client object
To your question: normally when you execute a request to the Exchange within the response you also get the version of the responding Exchange server. See the header element in the documentation at https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/expanddl-operation#successful-expanddl-response-example Although you don't get a good readable year version this version number corresponds to a certain version.
Having said this, you can for example make a first simple dummy request like expandDL with a dummy mail address and get then the version for all your subsequent requests. Or even better you set for your very first FindItem request the version to 2007 and retrieve then with the response the correct version.
Another option would be to set your request version always to 2007 which is the lowest possible. You can do this if you don't need functionality from later Exchange Versions like GetInboxRule or GetPhoneCallInformation.

How to set Google Play `inAppUpdatePriority` using google-php-api-client

I found following thread at : https://issuetracker.google.com/issues/133299031#comment14
Hello, In-app update priority of the release can be set using the Play Developer Publishing API's ⁠Edits methods. There is a new 'inAppUpdatePriority' field under ⁠Edits.tracks.releases. The documentation does not mention the new field yet but you should still be able to set it. In-app update priority can not be set from the Google Play Console at the moment.
I am using google-api-php-client with Service Account authentication, I would like to ask how to set 'inAppUpdatePriority' using google-api-php-client I have tried following in my PHP code.
$publisher->edits_tracks->update(self::PACKAGE_NAME, self::EDIT_ID, 'production', new \Google_Service_AndroidPublisher_Track);
After hours of testing with Google API PHP Client, I managed to edit the inAppUpdatePriority field, with Laravel, this way:
try {
$packageName = "your.package.name";
$versionCode = "version_code_as_string"; //example "50"
$client = new \Google\Client();
//you need to setup your own Service Account or other API access methods
$client->setAuthConfig("path/to/your/json/file");
$client->addScope(AndroidPublisher::ANDROIDPUBLISHER);
$service = new \Google\Service\AndroidPublisher($client);
//create new edit
$appEdit = $service->edits->insert($packageName, new \Google\Service\AndroidPublisher\AppEdit());
//uncomment if you want to get hold of available tracks
// $tracksResponse = $service->edits_tracks->listEditsTracks($packageName, $appEdit->id);
// dd($tracksResponse);
$trackRelease = new \Google\Service\AndroidPublisher\TrackRelease();
$trackRelease->versionCodes = [$versionCode];
//set desired update priority
$trackRelease->inAppUpdatePriority = 5;
$trackRelease->status = "completed";
$postBody = new \Google\Service\AndroidPublisher\Track();
$postBody->setReleases([$trackRelease]);
//desired track to update. One of the followings: production,beta,alpha,internal
$track = "production";
$update = $service->edits_tracks->update($packageName, $appEdit->id, $track, $postBody);
//commit changes to Google Play API
$service->edits->commit($packageName, $appEdit->id);
// dd($update);
} catch (Exception $ex) {
if ($ex->getCode() == 404) {
//this catches if some info is wrong (tested with a version code that has not been upload to Google Play Console)
}
}
Notes:
You should note that for this to work (without implementing your propre way of uploading app via Google Play API), you need to first upload your app via Google Play Console to your desired track, then click Save, then Review release and */!\DON'T CLICK Rollout release/!*, then run the above mentioned code which will Commit (Rollout) the changes (if you try to rollout release after running the above code, you will get an error that you can ignore).
Any changes to inAppUpdatePriority won't be applied if your release is already rolled out.
You should have already published at least one release in the desired track before you can use this (tested with Internal testing only)

Webscraping Symfony/Panther: Can't get HTML

I want to scrape a site with the symfony panther package within a Laravel application. According to the documentation https://github.com/symfony/panther#a-polymorphic-feline I cannot use the HttpBrowser nor the HttpClient classes because they do not support JS.
Therefore I try to use the ChromClient which uses a local chrome executable and a chromedriver binary shipped with the panther package.
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'http://example.com');
dd($crawler->html());
Unfortunately, I only receive the empty default chrome page as HTML:
<html><head></head><body></body></html>
Every approach to do something else with the $client or the $crawler-instance leads to an error "no nodes available".
Additionally, I tried the basic example from the documentation https://github.com/symfony/panther#basic-usage --> same result.
I'm using ubuntu 18.04 Server under WSL on Windows and installed the google-chrome-stable deb-package. This seemed to work because after the installation the error "the binary was not found" does not longer occur.
I also tried to manually use the executable of the Windows host system but this only opens an empty CMD window always reopened when closing. I have to kill the process via TaskManager.
Is this because the Ubuntu server does not have any x-server available?
What can I do to receive any HTML?
So, I'm probably late, but I got the same problem with a pretty easy solution: Just open a simple crawler with the response content.
This one differs from the Panther DomCrawler especially in methods, but it is is safer to evaluate HTML structures.
$client = Client::createChromeClient();
$client->request('GET', 'http://example.com');
$html = $client->getInternalResponse()->getContent();
$crawler = new Symfony\Component\DomCrawler\Crawler($html);
// you can use following to get the whole HTML
$crawler->outerHtml();
// or specific parts
$crawler->filter('.some-class')->outerHtml();
$client = Client::createChromeClient();
$crawler = $client->request('GET', 'http://example.com');
/**
* Get all Html code of page
*/
$client->getCrawler()->html();
/**
* For example to filter field by ID = AuthenticationBlock and get text
*/
$loginUsername = $client->getCrawler()->filter('#AuthenticationBlock')->text();

Error :service account does not have bigquery.jobs.create permission

I created one service account with role big query admin.I am Using big query PHP API. Let me know if any other permission is required or not?
It gives me an error stating that the:
service account does not have bigquery.jobs.create permission.
I wanted to run a query on bigquery. Please help.
Following is my code:
$service = new Google_Service_Bigquery($client);
$query = new Google_Service_Bigquery_QueryRequest($client);
$query->setQuery('SELECT * FROM [xxx:xxx.xxs] LIMIT 1000;');
$jobs = $service->jobs;
$response = $jobs->query($project_id, $query);
// Do something with the BigQuery API $response data
print_r($response)
;
I ran into this problem using the BQ library for nodejs.
It seems being signed into a user/service account via the CLI is not always enough. My service account was authenticated and had the correct permissions in the GCP SDK Shell, but I still got service account does not have bigquery.jobs.create permission..
I was able to fix this by simply adding the same service account details, using the client library methods. I used https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html.
In the case of nodejs, I just had to add
// Imports BigQuery library
const {BigQuery} = require('#google-cloud/bigquery');
// Create BQ Options - this object is what fixed the issue
const bqOptions = {};
bqOptions.projectId = '*your-project-name*';
bqOptions.keyFilename = '*Path-to-service-account-private-key*';
// Creates BQ client
const bq = new BigQuery(bqOptions);
I know you are using the PHP library, but I think the PHP equivalent would work the same.

Categories