How to send timezone to dialogflow request using php script? - timezone

We have a chat interface which we are using to request to dialogflow. Here the chat window is designed in php.
Now the chat can be initiated in any location, so when user connects we are also trying to capture timezone and send in the request to dialogflow. Based on the timeZone the results also differ.
Now i used the below code to append timezone, based on api considered from github in php.
GIT HUB link from where i have taken the code
https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/dialogflow/src/detect_intent_texts.php
The script taken from git hub is as follows
// Actual Script
// START dialogflow_detect_intent_text
//namespace Google\Cloud\Samples\Dialogflow;
use Google\Cloud\Dialogflow\V2\SessionsClient;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\QueryInput;
use Google\Cloud\Dialogflow\V2\QueryParameters;
use Google\Cloud\Dialogflow\V2\SessionEntityTypesClient;
use Google\Cloud\Dialogflow\V2\EntityTypesClient;
use Google\Cloud\Dialogflow\V2\ContextsClient;
function detect_intent_texts($projectId, $texts, $sessionId, $languageCode = 'en-US')
{
$test = array('credentials' => 'apikey/test-cd4f0-XXXXX.json');
// new session
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
printf('Session path: %s' . PHP_EOL, $session);
// query for each string in array
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput);
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$confidence = $queryResult->getIntentDetectionConfidence();
// output relevant info
$fulfilmentText = $queryResult->getFulfillmentText();
$sessionsClient->close();
}
echo detect_intent_texts('vehicle-test-cd4f0','text chat','123456','en-US','America/New_York');
// END dialogflow_detect_intent_text
Environment Details
OS : Linux
PHP 7.1
dialogflow v2
I have modified the script when sending data from detectIntent.
But my queryParams object returns me empty data, therefore the default timezone mentioned in the agent is considered. My main concern is to send TimeZone in the request. Which i am able to do with the online testing in google cloud interface https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.sessions/detectIntent?apix=true. The same implementation is not working for me. What i am doing wrong? Please suggest.
/*
Modified script
All the other statements
*/
// I tried to add this code before the detectintent method to get timezone but the variable returns empty data.
// get response and relevant info
//queryParams optional adding new code before detectintent
$optionalArgs = new QueryParameters();
$optionalArgs->setTimeZone('America/New_York');
$optionalArgs->getTimeZone();
$optionArgs = (array)$optionalArgs;
$response = $sessionsClient->detectIntent($session, $queryInput, $optionArgs);// I have added $optionArgs for adding time zone
// other statements
//
// end of code

Related

Access session value in gatling checks

I use gatling to send data to an ActiveMQ. The payload is generated in a separate method. The response should also be validated. However, how can I access the session data within the checks
check(bodyString.is()) or simpleCheck(...)? I have also thought about storing the current payload in a separate global variable, but I don't know if this is the right approach. My code's setup looks like this at the moment:
val scn = scenario("Example ActiveMQ Scenario")
.exec(jms("Test").requestReply
.queue(...)
.textMessage{ session => val message = createPayload(); session.set("payload", payload); message}
.check(simpleCheck{message => customCheck(message, ?????? )})) //access stored payload value, alternative: check(bodystring.is(?????)
def customCheck(m: Message, string: String) = {
// check logic goes here
}
Disclaimer: providing example in Java as you don't seem to be a Scala developper, so Java would be a better fit for you (supported since Gatling 3.7).
The way you want to do things can't possibly work.
.textMessage(session -> {
String message = createPayload();
session.set("payload", payload);
return message;
}
)
As explained in the documentation, Session is immutable, so in a function that's supposed to return the payload, you can't also return a new Session.
What you would have to do it first store the payload in the session, then fetch it:
.exec(session -> session.set("payload", createPayload()))
...
.textMessage("#{payload}")
Regarding writing your check, simpleCheck doesn't have access to the Session. You have to use check(bodyString.is()) and pass a function to is, again as explained in the documentation.

How to parse attachment values with strongGrid inbound webhook

Hello there I have setup successfully inbound webhook with strongGrid in net core 3.1.
The endpoint gets called and I want to parse value inside the attachment which is csv file.
The code I am using is following
var parser = new WebhookParser();
var inboundEmail = await parser.ParseInboundEmailWebhookAsync(Request.Body).ConfigureAwait(false);
await _emailSender.SendEmailAsyncWithSendGrid("info#mydomain.com", "ParseWebhook1", inboundEmail.Attachments.First().Data.ToString());
Please note I am sending an email as I don t know how to debug webhook with sendgrid as I am not aware of any cli.
but this line apparently is not what I am looking for
inboundEmail.Attachments.First().Data.ToString()
I am getting this on my email
Id = a3e6a543-2aee-4ffe-a36a-a53k95921998, Tag = HttpMultipartParser.MultipartFormDataParser.ParseStreamAsync, Length = 530 bytes
the csv I need to parse has 3 fields Sku productname and quantity I'd like to get sku values.
Any help would be appreciated.
The .Data property contains a Stream and invoking ToString on a stream object does not return its content. The proper way to read the content of a stream in C# is something like this:
var streamReader = new StreamReader(inboundEmail.Attachments.First().Data);
var attachmentContent = await streamReader.ReadToEndAsync().ConfigureAwait(false);
As far as parsing the CSV, there are literally thousands of projects on GitHub and hundreds on NuGet with the keyword 'CSV'. I'm sure one of them will fit your needs.

Jenkins - Next Execution plugin - How to get details through REST API

In my Jenkins i have installed a new plugin to see next executions details
Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Next+Executions
I can see that in Jenkins dashboard successfully but how can i access its details through REST API, like the way we do for all other stuff in Jenkins.
I am using Java to access Jenkins via REST API.
Thanks
UPDATED in 2016.9.20 the REST API is supported from release 1.0.12
<jenkinsurl>/view/<viewname>/widgets/<n>/api/json?pretty=true
see detail for the ticket JENKINS-36210
Below is left for reference
Though the REST API doesn't exist, I share the html parse python code sample for reference
It use the internal lxml code to parse and generate the list of the data, key code segment here
html = urllib2.urlopen(url, context=CTX).read()
# use beautifulSoup4 instead of lxml is better, but it is not default
html2 = lxml.html.fromstring(html)
div = html2.get_element_by_id("next-exec") # key id !!
result = lxml.html.tostring(div)
tree = lxml.html.fromstring(result) # ugly, but it works
trs = tree.xpath('/html/body/div/div/table/tr')
for tr in trs:
tds = tr.xpath("td")
url = tds[0].xpath("a/#href")[0]
jobname = tds[0].text_content()
datetime = tds[1].text_content()
status.append((datetime, jobname, url))
return status
see detail in https://gist.github.com/larrycai/6828c959f57105ca93239ca6aa4fc6fa

Attach POST data to BackgroundDownloader

I am implementing a Windows Phone 8.1 application that creates BackgroundDownloaders to restore cloud files back to the phone.
The cloud requires to POST the file ID as an additional JSON POST request and i cannot find a way to define it the BackgroundDownloader object.
Any ideas?
The way to do it is by creating a temp file to hold the JSON post data and send it to the CreateDownload function (as the last StorageFile parameter).
In addition, i added a Content-Type header to describe it (for me it is application/x-www-form-urlencoded) and add it with SetRequestHeader.
//set the Content-Type header
BackgroundDownloader^ downloader = ref new BackgroundDownloader();
Platform::String^ SKey2 = ref new Platform::String(L"Content-Type");
Platform::String^ SValue2 = ref new Platform::String(L"application/x-www-form-urlencoded");
downloader->SetRequestHeader(SKey2, SValue2);
//Create a temporary file and write the POST data into it
StorageFile^ postDataFile = nullptr;
....
//Call CreateDownload with the postDataFile
downloader->CreateDownload(uri, file, postDataFile);
That worked for me.

How to authenticate to Active Directory using iOS app

I am trying to create and iOS app that takes a users credentials and verifies it with the AD server. Is there some built in library in xCode to do that, or is it third party?
Any advice on direction to look would be greatly appreciated.
Thanks
Zach
Ok, so this was the PHP i used to make the connection to the ldap server. i am not 100% sure what is happening here, i got this code from IT Coordinator at my company. I understand all the binding and searching parts, but i dont get the the ldap_set_option part of this whole thing. Anyway after setting it up this way, you can then call the URL of the php script and pass it parameters. take a look at the PHP, and the url example with be below.
<?php
//Connection parameters
$dn = "DC=network,DC=net";
$host = "ldap://ldap.network.com";
$port = 1111
$user = $_GET['user'];
$pass = $_GET['pass'];
//$user = "user#network.net";
//$pass = "pass";
$filter = "memberof";
$keyword = "CN=USSC_ALL,CN=Users,DC=network,DC=net";
$filter = "objectclass";
$keyword = "user";
$filter = "objectcategory";
$keyword = "CN=Person,CN=Schema,CN=Configuration,DC=network,DC=net";
//The real thing with PHP
if (!empty($keyword) and !empty($dn)) {
//Connect to the AD
$adConn = ldap_connect($host, $port) or die("Could not connect!");
//Set protocol verison
ldap_set_option($adConn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol1");
//Set referrals... Won't work without this...
ldap_set_option($adConn, LDAP_OPT_REFERRALS, 0) or die ("Could not set ldap protocol2");
//Bind the user
$bd = ldap_bind($adConn, $user, $pass) or die ("Could not bind");
echo $bd;
//End binding
ldap_unbind($adConn);
} else {
echo "<p>No results found!</p>";
}
?>
</body>
</html>
Ok so now all you have to do is pass a username and password to the script and it will return the bind. that will give you either true or false. meaning if it bound successfully it is a correct combination of username and password.
this is how i am calling it:
http://192.268.192.1/ldap.php?user=(username here)&pass=(password here)
This is the approach that i took, and i think it is a very simple answer.
So what I have been able to find out is that i need to use PHP to do this. By creating a php file on the server, i can use built in ldap protocol to take a user name and password to the ldap server for verification. The query should then return true or false. As soon as i get this working ill post my code

Resources