I just deployed the Watson Conversation plugin on Wordpress and its working very well - I can talk to Watson and he works just as he does in Bluemix.
However, I have no way to then see or manage the conversation history (aside from going into Bluemix).
The WP plugin has the api.php and app.js and I know one of these must at some point handle the text that the user inputs and Watson responds.
Does anyone know how I could save that conversation into my WP mySQL database, so I can analyze and work with it?
Thank you!
If this plugin is using Nodejs (because of app.js) you need to create one custom code for it. Probably, the app.js have the call for the Conversation Service.
If this is your case...
You need to access the Log from Conversation service and get the return, and after it, save inside one MySQL database.
Using the plugin mysql inside the app.js if the lib Watson-Developer-Cloud is inside the code. And access the Logs with getLogs function. Where the Conversationv1 is the call for this service.
For use the mysql lib, please follow the example code:
var mysql = require('mysql');
var connMySQL = function(){
return mysql.createConnection({
host: 'localhost',
user: 'yourUser',
password: 'yourPassword',
database: 'nameDatabase'
});
}
module.exports = function (){
return connMySQL;
}
I really recommend this project for you know the follow steps. In this case, the call for conversation service is the conversation variable, and for access the return, like entities, context varibles, etc, you will use the data return.
For example:
data.context.contextVariableInsideWatson
Official reference from IBM Developers: watson-developer-cloud/node-sdk
Repository with one simple project using Conversation from IBM Developers here.
Related
I am trying to create a webpage that uses data from a MariaDB. My current idea (which has been giving me a lot of trouble) is to just connect to the database from the app.js file, which is the main script for my index.html.
const dotenv = require("dotenv");
dotenv.config();
const mariadb = require("mariadb");
const pool = mariadb.createPool({
database: process.env.DATABASE,
host: process.env.HOST,
user: process.env.USER_TOKEN,
password: process.env.PASSWORD,
});
// the rest of the code involves selecting from the db, and parsing the data
However, I have been running into many issues. I'm not too knowledgeable on all this, but I found that I need to webpack the file if I want to be able to use the "require" keyword. But I could not figure that out as I kept running into weird issues when using Browserify; I think there may be an incompatibility with MariaDB. I also looked into using JS modules, but I am not sure if that is possible with MariaDB.
I am trying to come up with another solution, potentially using some sort of API to a back end, which would make the GET request to the database, but I feel like it should not have to be that complicated for my sake (I also wouldn't really know where to start with this). All I basically want to do, is make a GET request to a MariaDB when the page loads on the client's browser and display that data on the webpage. Is there a simple way to do this?
I suggest you use nodejs to connect and query database as it will greatly resolve a lot of overhead for you..
The easiest way i can think of is using a prisma starter template here
https://github.com/prisma/prisma-examples/tree/latest/javascript/script
It also gives the added advantage of the ORM function...
Hope it helps.
So I figured the best way to learn is to try and fail over and over. I am building a webapp, at least trying to. I am curious how to go about using node to query my db. I am able to make a connection to the db with my single app.js file.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'xxxxxxxx-us-east-1.rds.amazonaws.com',
port : '3306',
user : 'user',
password : 'password',
database : 'app'
});
connection.connect(function(err){
if(!err) {
console.log("Database is connected ... ");
} else {
console.log("Error connecting database ... ");
}
});
My problem, or lack of understand begins when I try to integrate this into my client-side js code. For instance say I wanted to trigger the db connection when a user uploads a photo.
var upload = s3.putObject({
Bucket: albumBucketName,
Key: photoKey,
Body: file,
ACL: "public-read",
});
var promise = upload.promise();
Can I include the app.js node file?
Sorry if this is a dumb question. I feel like I am missing some fundamental understanding of how to integrate the functionality of node with my current client side JS. Any help or further reading is appreciated--I am even curious about PHP solutions.
X
Server and client side code are separate. However you can create a Node module that harnesses the AWS and returns an appropriate response to the client after completed.
To do this, you need to create an endpoint that you post your data to from the client, then process with the same AWS modules only for Node. You also need to be able to access the connection instance from a different NodeJS module. This can be accomplished several ways. First, if the library that instantiates the connection tracks all of the connections, you should be able to require the library in a different module, then use the library's API to access one of the connections. Second, if you create only one instance of the connection and allow it to export, then you can import the module with that connection. Third, you can use something like a request/response pattern between the two modules, with the pattern instance declared globally.
I'm trying to test out if PHP works from my Firebase hosting using the following:
(index.html)
<form action="welcome.php" method="post">
<input type="submit">
</form>
(welcome.php)
<?php
$to = "my#email.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: dummy#email.com";
mail($to,$subject,$txt,$headers);
?>
Every time I try this the browser keeps on attempting to open the PHP file rather than processing it. Is simple PHP enabled on the Firebase server hosting to process a simple form like this? If I can get it to work this way, I will be building the form out correctly including validation etc.
Thanks,
From the Firebase Hosting site (emphasis mine):
We deliver all of your static content (html, js, images, etc.) over a secure SSL connection and serve it on a CDN.
Firebase Hosting is for hosting static assets. Firebase currently doesn't offer any way to execute your code on Firebase's servers.
Update (2018-08-08): You can now run Node.js/JavaScript code but connecting your Firebase Hosting project to Cloud Functions + Firebase Hosting. But that still won't allow you to run PHP code.
As per the latest update firebase has started using Cloud Functions
Cloud Functions for Firebase lets you run mobile backend code that automatically responds to events triggered by Firebase features and HTTPS requests. Your code is stored in Google’s cloud and runs in a managed environment. There's no need to manage and scale your own servers.
For more : https://firebase.google.com/docs/functions/
There is no PHP but nodeJS available for server-side scripting ...
Google Cloud Functions are written in JavaScript, and execute in
a Node.js runtime.
Mandrill also supports nodeJS and it features a Webhooks API.
Therefore, one can require that node module within these "cloud functions" and "web hooks" ...and then post with a HTML form onto them.
There would need to be a few HTTP cloud functions defined on the Firebase Console, in order to let them subscribe, unsubscribe and manage their subscriptions. One could even generate the HTML markup for the input form with cloud functions and then attach it. As an example, not tested and no guarantee included:
const functions = require('firebase-functions');
const mandrill = require('mandrill-api/mandrill');
var client = new mandrill.Mandrill('YOUR_API_KEY');
/* TODO: add the user on Firebase, respond through the API */
exports.user_add = functions.https.onRequest((req, res) => {
});
/* TODO: change subscription settings on Firebase, respond through the API */
exports.user_edit = functions.https.onRequest((req, res) => {
});
/* TODO: remove the user on Firebase, respond through the API */
exports.user_remove = functions.https.onRequest((req, res) => {
});
/* optional: generate the HTML markup of the form, send HTTP response */
exports.markup = functions.https.onRequest((req, res) => {
});
One can bind the events of Firebase Auth, to keep two user databases in in-sync (this is not required for Mandrill, but required for MailChimp - no matter whether using the PHP or nodeJS wrapper):
exports.on_user_create = functions.auth.user().onCreate(event => {
const user = event.data;
});
exports.on_user_delete = functions.auth.user().onDelete(event => {
const user = event.data;
});
Firebase on Websites explains it, while there is a Local Emulator for Cloud Functions.
You can play around with any of these: Angular, Ember, Knockout, React,
Node JS. The same thing you PHP code does you can make happen with pretty much any Javascript technologies - just no dynamic language. Also another way to do it is to used an online form providers like Jot Forms or others. You can create and style the form withing you online form account then simply add it to you site. Then when user post it will post to the form. As a result you have a centralized environment not only for you current site but for any others down the road. You can create a web service and post values there - then do whatever you want with them: save them to the database... Otherwords have another server that handles all those things so you can just call it from Firebase hosted sites. Hope that helps
PS: I am currently building a product that is a simplified version of Online Forms to be used on Firebase websites. I am planning to have a few people using for now so if you would like you can email me and I will create an account for you to use it. As long as there is no abuse like sending a bunch of emails - you will be fine!
I have an IOT hub getting some data. I also have an Azure function app in js that is triggered when an IOT event occurs. In the function app, I want to query the incoming data against a azure sql database.
In the azure function->application settings->connection string, I created a connection string x with value of the azure db connection string. My index.js file is as below.
module.exports = function (context, IoTHubMessages) {
context.log(`JavaScript eventhub trigger function called for message array ${IoTHubMessages}`);
IoTHubMessages.forEach(message => {
context.log(`Processed message ${message}`);
var sqlConnection = x;
});
context.done();
};
I get an error that x is not defined. How can I access x? Also how how to execute a select query from here.
Any help will be greatly appreciated.
Try accessing your app setting using process.env["x"] Here are the docs, and here's a related issue you may face if you're trying to run this locally.
I don't have experience writing Javascript functions to execute a select query, but this documentation seems like a good place to start: Use Node.js to query Azure SQL Database
There is no easy way to access connection strings in Node.js.
Instead, the suggestion is to use app settings for all your secrets and connection strings. You can them access them using process.env.YourAppSetting.
See similar questions one and two.
I'm trying to connect from my Google Apps Script project to my Google Cloud SQL (second generation) instance. Here's the code I've got now.
I was able to connect to it successfully when connecting thru IP, but that's unencrypted. All of the Google Apps Script IPs are whitelisted also.
If my Instance ID is 12345 then my Instance connection name is 12345:us-west1:12345.
var conn = Jdbc.getCloudSqlConnection('jdbc:google:rdbms://instanceConnectionName/database',{user: 'username', password: 'password'});
I've tried:
Taking the username and password out of the curly braces, so it's just string, string, string
Using the instance name (keep in mind the difference between Instance ID and Instance connection name)
Removing the database
Removing the //
Switching authentication modes (AuthMode.LIMITED and AuthMode.NONE)
A whole bunch of other stuff
So basically, I just can't figure it out and some help would be appreciated it. Thank you!
Google's documentation is difficult to understand here. Basically, they tell you that the connection url must look like this:
var conn = Jdbc.getCloudSqlConnection('jdbc:google:rdbms:subname');
However, for a MySQL database, it must look like this:
var conn = Jdbc.getCloudSqlConnection('jdbc:google:mysql://subname');
Just replace rdbms with mysql. That's it.