I need to know if any of the EWS-JS API(e.g https://github.com/gautamsi/ews-javascript-api) supports EWS UserConfiguration object and its Update method to update OWA Signature.
Here is EWS+ PowerShell code, which I need to convert to EWS JS API, and execute from Node.js code:
$owaUserOptions= [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind( $exService,"OWA.UserOptions",
[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,
[Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All);
if (-not $owaUserOptions.Dictionary.ContainsKey("signaturehtml")) {
if (-not [System.String]::IsNullOrEmpty($HtmlSignature)) {
$owaUserOptions.Dictionary.Add("signaturehtml",$HtmlSignature)
}
}
$owaUserOptions.Update()
disclaimer: I am author of the lib. I was also approached by Laeeq privately on email. posting my answer for community benefit. code block uses typescript.
var HtmlSignature = "signature html";
UserConfiguration.Bind(service,"OWA.UserOptions", WellKnownFolderName.Root, UserConfigurationProperties.All)
.then(owaUserOptions =>{
if(!owaUserOptions.Dictionary.ContainsKey("signaturehtml")){
if(StringHelper.IsNullOrEmpty(HtmlSignature)){
owaUserOptions.Dictionary.Add("signaturehtml",HtmlSignature)
owaUserOptions.Update().then(()=>{
console.log("update complete");
});
}
}
});
Related
I am trying to do webhook fulfillment for my dialogflow agent. However there are four specific intents that should all have different JSON responses based on what specific intent is called. Right now I am creating a switch case based on the called intent's displayName. However that is not working. Should I be using a different parameter to check what intent is called other than displayName?
HERE IS MY CODE THAT ONLY OUTPUTS "test"
server.post("/get-bill-details", function(req, res) {
let intentName = req.body.queryResult.intent.displayName;
let ret = "test";
if(intentName == "1 - Bill"){
ret = "your billing amount is $120.";
}
return res.json({
fulfillmentText: ret,
source: "get-bill-details"
});
});
I would suggest you use client libraries as they will ease out the process of parsing the JSON and reduce your development time. You can use NodeJS or Python clients for Dialogflow. Also, if you need Google Assistant, you can also use following NodeJS library to build webhook. They all have documentation on how to build webhooks on cloud or by using Express and other frameworks.
Instead of matching with intent name give your intent an action name( try not to give any spaces e.g input.welcome ).
Then get the action parameter using
let action = req.body.queryResult.action;
switch(action) {
your logic..
}
Also as abhinav said you can use this library to ease your development time and better readability of your code that also help cross platform response for Cards, Image and Suggestions.
const { WebhookClient } = require('dialogflow-fulfillment');
server.post('/', function (request, response, next) {
const agent = new WebhookClient({ request, response });
const welcome = () => {
agent.add('Hello Welcome To My bot');
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
agent.handleRequest(intentMap);
}
I am relatively new to NodeJS, but I'm porting an existing API server written in PHP to use NodeJS. I started out looking at Express, but realised that with all the layout-rendering and templating stuff in Express, it wasn't suited for the task. Then I looked at Restify, but realised it's REST-ness wouldn't work with the model of this API.
I don't want anything that is tied to a database, or any specific way of setting out the API endpoints. Is the best solution to fully roll my own server, without the help of any libraries?
EDIT: Sorry, it seems I was unclear. I am trying to recreate the PHP API as close as possible, and the PHP version does not use REST. It has a few different PHP scripts which take some POST parameters.
If you just want a simple JSON API, Express is still an option. Layouts, temptating and middleware are optional, and you can just use simpler functions.
var express = require('express');
var app = express();
app.use(express.bodyParser());
app.post('/', function(req, res) {
// req.body is an object with POST parameters
// respond with JSON
res.json(200, { data: 'payload' })
// or show an error
res.json(500, { error: 'message' });
});
app.listen(80);
That is one of the simplest solutions available. Unless you want to do request body parsing, checking the HTTP request method, other things yourself, then you can create your own server. That would look more like this:
var http = require('http');
http.createServer(function(request, response) {
if (request.method === 'POST') {
var data = '';
request.on('data', function(chunk) {
data += chunk;
});
request.on('end', function() {
// parse the data
});
}
}).listen(80);
A method like so would also require checking the path as well as other things that would be handled automatically in Express.
I am trying to send some data from Dart to PHP...
This is the code i am using to send the data from Dart:
button.onClick.listen((e) {
var req = new HttpRequest();
req.onReadyStateChange.listen((HttpRequestProgressEvent e) {
if (req.readyState == HttpRequest.DONE) {
print('Data submitted!');
}
});
req.open('POST', form.action);
req.send('hello from dart');
});
In my PHP file I am trying to use the string i have send from dart, but count($_POST) returns 0. $_POST seems to be empty...
Dart code DOES trigger the php script and 'Data submitted' is printed...
This is actually related to your PHP configuration. You can access the POST'd data with PHP's reserved variable: $HTTP_RAW_POST_DATA However the preferred method is to use php://input
I am very new to Dart, but you can use FormData in the send. So a quick and dirty way could be.
var data_form = new FormData(query('#My_form'));
button.onClick.listen((e){
var request = new HttpRequest():
request.open('POST', 'http://Localhost/form_data.php');
request.send(data_form);
I am implementing socket.io server in node js (socketio.js) for my windows azure project. My worker role is in c#. And am sending a brokered message from worker role to socketio.js through service bus queue. But The object which am sending through the brokered message is not getting serialized into a json object. I dont know how to access the body of this brokered message in node js.
I can show how am sending the brokered message in the worker role and how am receiving it in the node js script.
The response body of brokered message(i.e message.body)
#rrayOfTestModelHhttp://schemas.datacontract.org/2004/07/Project.Model ☺i)http://www.w3.org/2001/XMLSchema-instance☺
TestModel is the name of the object model which am sending through the brokered message body.
Worker Role:
BrokeredMessage socketioMessage = new BrokeredMessage(messageObject);
WorkerRoleClient.Send(socketioMessage );
Node Js script:
serviceBusService.receiveQueueMessage(queue, function (error, receivedMessage) {
if (!error) {
console.log(receivedMessage);
if (receivedMessage != null) {
var messageBody = receivedMessage.body;
console.log(messageBody);
io.sockets.emit('news', messageBody);
}}
the message body i receive here is some plain unreadable string. And i am sending proper objects from the worker role. Please let me know if any of you have an idea about whats going wrong
Thanks
I finally found a way to de serialize it and getting the json objects.
Worker Role in C#
var recordsMessage = Newtonsoft.Json.JsonConvert.SerializeObject(data);
BrokeredMessage socketMessage = new BrokeredMessage(recordsMessage);
Receiving in Node js:
if (receivedMessage != null) {
var messageBody = receivedMessage.body;
var jsonString = messageBody.substring(messageBody.indexOf('['), messageBody.indexOf("]")+1);
var recordsQueue = JSON.parse(jsonString);
}
Hope this helps someone
I know it's an old ticket but i guess it might help people in the future as it helped me today :).
Instead of using substring from your nodejs app, you have the possibility to directly send the message in string without the automatic serialization.
To do so, use the following code :
using (Stream stream = new MemoryStream())
using (TextWriter writer = new StreamWriter(stream))
{
writer.Write("Start");
writer.Flush();
stream.Position = 0;
queueClient.Send(new BrokeredMessage(stream) { ContentType = "text/plain" });
}
Hope it will help,
Clément
I am also trying to find a reference to help doing this, please check the following link: http://www.rackspace.com/blog/node-swiz-node-js-library-for-serializing-deserializing-and-validating-objects-in-rest-apis/
it shows the serialization and the deserialization using Node JS in any of the requested format (JSON or XML)
let me know if this work with you :)
Developers of the Drive SDK - or generally, the OAuth2.0 PHP client library!
In the apiClient.php there is a setAccessToken function:
public function setAccessToken($accessToken) {
if ($accessToken == null || 'null' == $accessToken) {
$accessToken = null;
}
self::$auth->setAccessToken($accessToken);
}
The #param of this function is something like this:
{"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
"expires_in":3600, "id_token":"TOKEN", "created":1320790426}
Why you name this parameter $accessToken if the access token is just a part of this JSON encoded string ??
It's very misleading i think.
When we go deeper and look at: $auth->setAccessToken($accessToken); in apiOAuth2.php
we see:
public function setAccessToken($accessToken) {
$accessToken = json_decode($accessToken, true);
if ($accessToken == null) {
throw new apiAuthException('Could not json decode the access token');
}
if (! isset($accessToken['access_token'])) {
throw new apiAuthException("Invalid token format");
}
$this->accessToken = $accessToken;
}
Look at the second if: $accessToken['access_token']. Whats the point of this? Access token inside an accessToken ?? :)
You should name the $accessToken parameter (the whole JSON string) of these functions to something else like $credentials or whatever because it's a little bit blurry... but tell me if I'm wrong.
As some of the comments mention I would post this either on the Google APIs PHP client library form: https://groups.google.com/forum/?fromgroups#!forum/google-api-php-client
Or file an issue on their issue tracker: http://code.google.com/p/google-api-php-client/issues/list
This will make sure that the engineers working on the PHP client library will be aware of this.
And you are right this makes perfect sense :)