how to send json using wt? - c++

I'm trying a C++ framework for web development - Wt (WebToolkit).
I want to extract data from text fields, create json-object and send it to the server by POST.
void LoginForm::sendLogInRequest()
{
Json::Object data;
data["username"] = usernameTextEdit->text();
data["password"] = passwordTextEdit->text();
}
then I want to send data. how can I do this?

There's a Wt::Http::Client that can post that data for you. The manual has a usage example.

Related

Taking response from grpc in clojure

I am working with some clojure and need to call a grpc based endpoint.
ExampleGrpcRequest {
string name = 1
}
ExampleGrpcResponse {
repeated string Books = 1
}
Book {
string name = 1
int pages = 2
}
service ExampleService {
rpc GetBook(ExampleGrpcRequest) returns (ExampleGrpcResponse) {}
}
This is my grpc request/response struct. I want to parse the response from an api call in Clojure and map it to another object. I even tried searching some resources but couldn't find much on the same lines.
This is core clojure based question
grpc proto used are based on java
getBooks() would return an a list of books.
Edit:
Making my Question a bit clear-
How do I parse grpc response in clojure? Is there any efficient way to do it? I checked out some blogs & didn't understood.
As I am new to clojure & grpc, I want to undestand is this similar to
how we parse a grpc response in Java? i.e.
If I would want to parse a grpc response from a java client-
I would do something like:
ExampleGrpcResponse.GetBooks().get(0).getName();
ExampleGrpcResponse.GetBooks().get(0).GetPage();

DocuSign JSON SOAP Request

I am trying to understand how to send SOAP requests with JSON formatted data to docusign. Following this guide is only for pdfs:
https://developers.docusign.com/docs/esign-soap-api/how-to/request-signature/
I created a template on docusign developer and downloaded it, which is in json format.
How do I send the data in that format? Is it currently stored as documentBase64, do I need to convert it the data to a PDF, or just set the documents bytes to that value (doc.PDFBytes)? Attempting to do the ladder, gives me a soap error:
Soap Fault: The validation of the PDF file failed.
What fields are required to pull out of the json at minimum?
Yes, I have the envelope, recipient and tabs set up. I currently am able to send PDFs as is to get signed, just not json formatted data.
Here is an example of attempting to pull out the documentbase64 data and set it to the pdfbytes field:
string pdfbytes = json4.value("documentBase64", "oops");
doc->PDFBytes = new xsd__base64Binary();
size_t pdfSize = 0;
// Double conversion to get it to match the datatype for *PDFBytes->ptr*
const unsigned char* t = reinterpret_cast<const unsigned char *>( pdfbytes.c_str() );
unsigned char* y = const_cast<unsigned char*>(t);
doc->PDFBytes->__ptr = y;
doc->PDFBytes->__size = pdfbytes.size();
UPDATE:
Solved my own problem. You will need to decode your base64 data from docusign. I used the following decoder:
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp/
Updated code:
string pdfbytes = json4.value("documentBase64", "oops");
std::string decoded = base64_decode(pdfbytes);
Unless you have a really good reason, I highly recommend you consider using the DocuSign eSignature REST API and not the DocuSign eSignature SOAP API.
Not every feature is supported by the SOAP API.
You could use https://github.com/jgaa/restc-cpp to make REST API calls from a C++ codebase.
Also, remember that documents sent in the API has to be base64 encoded. This goes for both REST and SOAP.

Is it possible to use AMAZON LEX to build a chatbot which connects with database and Web service stored on client side?

Our organization wants to develop a "LOST & FOUND System Application" using chatbot integrated in a website.
Whenever the user starts the conversation with the chatbot, the chatbot should ask the details of lost item or item found and it should store the details in database.
How can we do it ?
And can we use our own web-service because organization doesn't want to keep the database in Amazon's Server.
As someone who just implemented this very same situation (with a lot of help from #Sid8491), I can give some insight on how I managed it.
Note, I'm using C# because that's what the company I work for uses.
First, the bot requires input from the user to decide what intent is being called. For this, I implemented a PostText call to the Lex API.
PostTextRequest lexTextRequest = new PostTextRequest()
{
BotName = botName,
BotAlias = botAlias,
UserId = sessionId,
InputText = messageToSend
};
try
{
lexTextResponse = await awsLexClient.PostTextAsync(lexTextRequest);
}
catch (Exception ex)
{
throw new BadRequestException(ex);
}
Please note that this requires you to have created a Cognito Object to authenticate your AmazonLexClient (as shown below):
protected void InitLexService()
{
//Grab region for Lex Bot services
Amazon.RegionEndpoint svcRegionEndpoint = Amazon.RegionEndpoint.USEast1;
//Get credentials from Cognito
awsCredentials = new CognitoAWSCredentials(
poolId, // Identity pool ID
svcRegionEndpoint); // Region
//Instantiate Lex Client with Region
awsLexClient = new AmazonLexClient(awsCredentials, svcRegionEndpoint);
}
After we get the response from the bot, we use a simple switch case to correctly identify the method we need to call for our web application to run. The entire process is handled by our web application, and we use Lex only to identify the user's request and slot values.
//Call Amazon Lex with Text, capture response
var lexResponse = await awsLexSvc.SendTextMsgToLex(userMessage, sessionID);
//Extract intent and slot values from LexResponse
string intent = lexResponse.IntentName;
var slots = lexResponse.Slots;
//Use LexResponse's Intent to call the appropriate method
switch (intent)
{
case: /*Your intent name*/:
/*Call appropriate method*/;
break;
}
After that, it is just a matter of displaying the result to the user. Do let me know if you need more clarification!
UPDATE:
An example implementation of the slots data to write to SQL (again in C#) would look like this:
case "LostItem":
message = "Please fill the following form with the details of the item you lost.";
LostItem();
break;
This would then take you to the LostItem() method which you can use to fill up a form.
public void LostItem()
{
string itemName = string.Empty;
itemName = //Get from user
//repeat with whatever else you need for a complete item object
//Implement a SQL call to a stored procedure that inserts the object into your database.
//You can do a similar call to the database to retrieve an object as well
}
That should point you in the right direction hopefully. Google is your best friend if you need help with SQL stored procedures. Hopefully this helped!
Yes its possible.
You can send the requests to Lex from your website which will extract Intents and Entities.
Once you get these, you can write backend code in any language of your choice and use any DB you want.
In your use case, you might just want to use Lex. PostText will be main function you will be calling.
You will need to create an intent in Lex which will have multiple slots LosingDate, LosingPlace or whatever you want, then it will be able to get all these information from the user and pass it to your web application.

EmberJS client side record management (ember-data)

I have just started trying to use ember-data. I have an ember app for which I need to produce all the data on the client side and then save it all at once. So my object graph has a "Project" as the root object, then a project can have many "Sections" and then each section can have many "Items".
I am up to the stage where I am trying to create Item records on the client side and add them to the correct Section. When I am ready to save the data I just want to use project.save() and have it go and save the object graph instead of saving every time the model changes.
I am trying to look up the section to place the items in by name using store.filter({name:"section1"}) but ember keeps trying to go to the server to look them up. I see this in the console: GET http://localhost:4200/sections?name=Section1 404 (Not Found).
This is what I am trying to do:
store.filter('section', {name:'Section1'}, function(section) {
return section;
}).then(function(section)
{
var record;
//create a record
section.pushObject(record);
});
You are doing server side filtering and you want client side filtering.
Please read this article carefully.
In short, you should do
store.filter('section', function(section) {
return section.get('name') == 'Section1';
});

Growl Notifications from a Web Server

I notice that Growl allows for the possibility of Growl notifications from a website. Has anyone tried implementing this?
If so, what form did it take? Did you implement multi user support? And, can you provide any code examples (C# or Objective-C would preferable but I'm not that fussed)?
Rich
There are GNTP (Growl Network Transport Protocol) bindings for various languages, a list of bindings can be found here - these allow you to send notifications from, say, a PHP script.
I wouldn't trust Growl's UDP system directly, but rather write a server that receives and stores notifications (maybe as a tiny web app), and a local script that routinely grabs any new messages via HTTP and Growls them. Not complicated at all, will be more reliable than UDP, and can queue up messages when your Growl'ing machine is powered-off or unreachable. Shouldn't take long to implement
Basically, server.php in pseudo-PHP (which could use Net_Growl):
<?php
if($_GET['action'] == "store"){
$title = $_POST['title'];
$message = $_POST['message'];
$password = sha1($_POST['password']);
if($password == "..."){
store_in_database(sanitise($title), sanitise($message);
}
} else {
print(json_encode(get_notifications_from_database()));
mark_notifications_as_read();
}
?>
client.py in pseudo-Python (which could use gntp):
while 1:
time.sleep(60):
data = urllib.urlopen("http://myserver.com/server.php?action=get&password=blah").read()
for line in data:
notif = json.decode(line)
growl.alert(notif['title'], notif['message'])