How to include bluemix text to speech services using Node - ibm-cloud

I have a bluemix app using dialog service and I am trying to include the text to speech service using:
var watson = require('watson-developer-cloud');
in my index.js.
I get an undefined error.
I already tried adding npm install watson-developer-cloud on the build pipeline but it does not work. I also tried browserify.

In your app.js declare
var watson = require('watson-developer-cloud');
app.get('/test', function(req, res) { //call all req function here });
In your Index.js Add
$('#text_to speech').click(function(e){
$.ajax({ type: 'GET', data: { text: "text to speech" }, url: '/test' , success: function(response) { console.log('success'); } });
}

Without looking at more of your build pipeline, it's difficult to see if your npm install command is running correctly. I suggest you add watson-developer-cloud to the dependencies list in your package.json

Related

CLI arguments of create-nx-workspace

Is there some documentation regarding the arguments that create-nx-workspace takes? I'd like to build a copy and paste-able oneliner to set up a new workspace without any interactive questions asked. So far I have
npx create-nx-workspace#latest myworkspace --name myworkspace --preset web-components --appName myapp --cli angular
Next it's asking me which default stylesheet format I want to use. And I can't figure out how to specify that as a command line parameter.
Currently there is not option to define style within create-nx-workspace command. As you can see there is only prompt to inquire style after determination of appName promise:
determineWorkspaceName(parsedArgs).then(name => {
determinePreset(parsedArgs).then(preset => {
return determineAppName(preset, parsedArgs).then(appName => {
return determineStyle(preset).then(style => {
return determineCli(preset, parsedArgs).then(cli => {
const tmpDir = createSandbox(packageManager, cli);
createApp(tmpDir, cli, parsedArgs, name, preset, appName, style);
showCliWarning(preset, parsedArgs);
showNxWarning(name);
pointToTutorial(preset);
});
});
});
});
});
Code of the determineStyle is here.
I have already prepared PR to add this feature into create-nx-workspace command here.
You may select the tools used for styling the application
npx create-nx-workspace#latest myworkspace ... --style=css
You may use on of the following options
css, scss, less for Angular projects
styl for all non-Angular, and
styled-components, #emotion/styled, styled-jsx for React, Next.js and Gatsby.
Command line options for NX
You can check the command line options that you can use to create the NX workspace by running
npx create-nx-workspace#latest --help
The following are the command line options for the v13.4.5 version:
Option
Description
preset
Tools to be used in the workspace (options: "apps", "empty", "core", "npm", "ts", "web-components", "angular", "angular-nest", "react", "react-express", "react-native", "next", "gatsby", "nest", "express")
appName
Name of the application
cli
CLI to be used (options: "nx", "angular")
style
style option (options: "css", "scss", "less" for Angular, "styl" for all non-Angular and "styled-components", "#emotion/styled", "styled-jsx" for React, Next.js and Gatsby)
interactive
enable interactive mode when using presets (boolean)
packageManager
package manager to use (npm, yarn, pnpm)
nx-cloud
yse Nx Cloud (boolean)

Office.JS “This add-in is no longer available” error when creating a Word Document with context.application.createDocument()

I'm developing an add-in for Microsoft Word 2016 using office js version 16.0.8626.1000. I use a web service to retrieve a document in base64 format and then I create a new Word instance with that.
The problem is that whenever I run the add-in from my server (not from visual studio debugger) it opens the document but the add-in frame displays an error
First Instance:
Second Instance:
This doesn't happen if I run the add-in from visual studio debugger, it opens the new instance without the frame.
This is my code
Office.initialize = function (reason) {
// Checks for the DOM to load using the jQuery ready function.
$(document).ready(function () {
$('#get').click(function () {
openWord();
});
});
}
This how I retrieve the document (without real url):
function openWord() {
getDocumentAsBase64(function (data) {
Word.run(function (context) {
var myNewDoc = context.application.createDocument(data);
context.load(myNewDoc);
return context.sync()
.then(function () {
myNewDoc.open();
context.sync();
})
.catch(function (myError) {
//otherwise we handle the exception here!
updateStatus(myError.message);
})
}).catch(function (myError) {
updateStatus(myError.message);
});
});
}
function getDocumentAsBase64(callback) {
$.ajax({
url: 'http://myurltomydocument.com/getFile',
data: "{}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (response) {
callback(response.d);
},
error: function (response) {
updateStatus(response.d);
}
});
}
EDIT -- 8/12/2017
This is the manifest that I'm currently using if anyone wants to replicate the problem with Office 2016
I don't read Spanish, but the error mentions Visual Studio. I think Office is still trying to run a version that was sideloaded with Visual Studio and it's telling you that it can't do that. The problem might be the manifest. I notice that it still has the string ~remoteAppUrl in many places. When you are debugging with VS, this string is automatically replaced with the localhost URL, but you need to manually change all these to your web service's domain and sideload the new manifest when you are going to run it from the web service.
EDIT 12/11/17:
If that doesn't fix it, try clearing the Office cache. Details are at: Clear the Office cache
Edit 12/19/17:
Try this:
Go on File->Info->Check for Issues -> Inspect Document -> Inspect.
Then on Task Pane Add-ins click Remove All
Finally I found the solution to this problem.
First I downloaded Office 2016 Administrative Template Files.
When you run it, it will extract a bunch of files and folders.
Enter admx folder and copy the whole content to C:\Windows\PolicyDefinitions.
Do a gpupdate /force under CMD (or Powershell) as an administrator.
Run gpedit.msc and find the Administrative Template for Office 2016 then Updates (PC configuration >> Administrative Template >> Microsoft Office 2016 >> Updates >> Update Channel) and set the Update Channel to Montly Channel.
I'm on Version 1711 (compilation 8730.2127 click and run) and everything is working good now.
EDIT 9/1/2018:
The error started showing up again. The only thing I did was attaching the runtime logging to debug my add-in manifest. This is still unsolved.

Run Gulp tasks web

Is possible to run gulp tasks from a UI page ?
Example: Having a web form or any type input and when you click on any button, to run a already defined and specific task(run build, compile sass, you name it.)
Thank you
Yes, you could. You just need to execute gulp taskname when needed. You would need an ajax request to a script that executes the gulp command. F.I., you can make a working example with this skeleton, using nodejs and express:
gulpfile
gulp.task('minify' , function(){
console.log('gulp called!');
gulp.src('scripts/src/test.js')
.pipe(minify() )
.pipe(gulp.dest('scripts/bin/'));
});
server.js
var express = require('express')
var app = express();
var exec = require('child_process').exec;
app.use(express.static('public'))
app.post('/send' , function(req , res){
console.log('this was called');
exec('gulp minify');
res.send('success!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
public/index.html
<html>
<head>
</head>
<body>
<button onclick=send()>Execute gulp minify</button>
</body>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script>
function send(){
$.ajax({
url : 'http://localhost:3000/send',
method : 'POST',
success : function(res){
console.log(res);
},
error : function(response){
console.log('Error!');
console.log(response);
}
});
}
</script>
</html>
package.json
{
"name": "gulp-from-script",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"gulp-uglify": "^2.0.0"
}
}
scripts/src/test.js
function test(){
console.log('this file should be minified to bin/test.js on click');
//end.
}
With that boilerplate, you can just install the dependencies
npm install
then serve:
node server.js
And then go to
localhost:3000/index.html
After clicking the button, a minified file should appear under /scripts/bin/test.js
Of course you need nodejs and npm installed on your system to get this to work. Is just a working example demonstrating how to do it, it could be done with any other server side technology, the only point is to call the gulpfile task from a post controller on your server side.
So, would this be useful for anything? As Sandrina Pereira states, gulp is a task runner meant for building the front-end assets of your project. You shouldn't call it from a script fired by a user of a web application.
However, you could set up this kind of system to create a local website or app under localhost/ to manage your builds, or perform any other task in your machine, from a UI. I don't know if that is just a good or desirable idea, but it is definitely doable.
Answer: I don't know, but if so, you shouldn't do it.
Why?: Gulp is meant to be a task runner on developing side, running and controlled by a shell (terminal /command line), not on web / browser side.
You can use React with Gulp. Web behaviour is handle on React side. You can easily learn React, there are a lot of documentation and tutorials. I like this one

Sails v10 Skipper and UUID

I have a Sails app and am uploading files with the following simple code in the relevant controller:
upload: function(req,res){
req.file('files').upload({
dirname: './uploads/',
maxBytes: 1000000
},function (err, uploadedFiles) {
if (err) {
return res.send(500, err);
} else {
return res.json({
message: uploadedFiles.length + ' file(s) uploaded successfully!',
files: uploadedFiles
});
}
});
}
In the docs it says that "By default, Skipper decides an "at-rest" filename for your uploaded files (called the fd) by generating a UUID and combining it with the file's original file extension when it was uploaded ("e.g. 24d5f444-38b4-4dc3-b9c3-74cb7fbbc932.jpg")."
This is not happening. My files are being saved in the './uploads/' folder with their original filenames. Just wondering where I'm going wrong for the UUID filenames to be missing. Or have I just misunderstood the docs?. I'm not getting any console warnings or errors. I really would like to have Skipper handle the unique naming of any files, just for simplicity.
I think the ground is probably shifting under your feet; what you're referring to is a very recent update. It works for me using the latest Skipper from Github, but it may not have been published to NPM just yet.
In addition to sgress454 comment:
Skipper is updated in the global sails-packages only 14 hours ago: https://github.com/balderdashy/sails/commit/3af77c42a5d8c7687e3d56eeefd9cffdfc24195b
This new packages.json may not be includes in the current npm install of "sails".
To solve this problem you can do:
cd yoursails_project/node_modules/sails
npm install skipper --save

modifying the bodyParser size in sails.js without having to modify the sails library sourcefile

I modified the bodyParser option size for posting huge strings through input forms in sails.
I did it the following way:
I went to: node_modules/sails/lib/express/index.js
And then I replaced the default bodyParser :
bodyParser = sails.config.express.bodyParser();
by
bodyParser = sails.config.express.bodyParser({limit: 8248242});
I works, but I suppose there must be an easier way to do it via parameters or something...
I tried to create an express.js file in the config folder like in https://gist.github.com/mikermcneil/8249181
but it does not seem to recognise the express module...
Any advice about what would be the best way to change the bodyParser size limit via some kind of parameter?
Cheers!
Thanks Scott! I don't know how this voting system works, but I am grateful for your help!! I had not realised that express was not explicitely added to the package.json and that sails has its own internal separate express distribution. I added express in package.json, and an express.js as follow in the config folder:
module.exports.express = {
express: {
bodyParser: function () {
return require('express').bodyParser({ limit: 8248242 })
}
}
};
and it now works after npm install... Thanks a lot!
The expected awswer won't work with Sails v10.
Here's the fix that worked for me.
You need to install the body-parser NPM
npm install body-parser
then add
bodyParser: function () { return require('body-parser')({ limit: 8248242 }) }
into config/http.js
This now works for me in Sails 1.2.3; specifically, using the example bodyParser in the default config/http.js:
...
bodyParser: (function _configureBodyParser(){
var skipper = require('skipper');
var middlewareFn = skipper({
// strict: true,
limit: '10mb',
});
return middlewareFn;
})(),
...