node JS and Out of Range Error - node.js

I'm trying to build my first node js application, to manage some telegram account. I don't want to create a telegram bot, which is making it really hard since most example relating to node js and telegram is bot related. I seem to be running into a lot of roadblocks, this being one of them...
I am trying initialize a connection to telegram, but I am getting the following error
internal/buffer.js:35
throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value);^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must
>= 0 and <= 4294967295. Received -2083955988
and it seems to be happening on this line of code
const { MTProto } = require('telegram-mtproto')
this is what the init.js file looks like
console.log('start init')
const { MTProto } = require('telegram-mtproto')
console.log('const MTProto set')
const api = {
invokeWithLayer: 0xda9b0d0d,
layer: 57,
initConnection: 0x69796de9,
api_id: 12345,
app_version: '1.0.1',
lang_code: 'en'
}
console.log('init api set')
const server = { webogram: true, dev: true }
const telegram = MTProto({ api, server })
console.log('init complete')
module.exports = telegram
I have put in a number of console.logs to try and trace out exactly where the error occurs, the first log of 'start init' prints and then the error happens, If I remove or comment out the
const{MTProto}=require('telegram-mtproto')
line then it will print the second log of 'cont MTProto set'. I am not sure why I am getting this error or exactly what it means or how to fix / avoid it.
I am using visual Studio 2017 and have added the the telegram-mtproto package in the package.json file like this.
{
"name": "test-telegram-login",
"version": "0.0.0",
"description": "testTelegramLogin",
"main": "server.js",
"dependencies": {
"crypto-address": "0.0.2",
"telegram-api": "^4.1.0",
"telegram-mt-node": "^0.9.7",
"telegram-mtproto": "^1.0.5"
},

I assume you need to update your WebSocket version or downgrade your Node.js version
I advice update the websocket module, in package.json file.
For example:
Change
"websocket": "^1.0.24"
to
"websocket": "^1.0.28"
Btw don't forget that you will need to delete your node_modules folder and do
npm install
for downloading all modules once again.
Of course if you don't want to download all modules, you can delete only ../node_modules/websocket folder and install websocket module.
npm install websocket

Related

Node modules with sub-directories: "Error parsing triggers: Cannot find module 'ibm-watson'"

I have a Firebase Cloud Function that calls IBM Watson to get a token. I'm updating it from the old username/password auth to the current IAM auth.
Here's the code from the IBM documentation:
const watson = require('ibm-watson');
const { IamAuthenticator } = require('ibm-watson/auth');
// to get an IAM Access Token
const authorization = new watson.AuthorizationV1({
authenticator: new IamAuthenticator({ apikey: 'fakekey-1234' }),
});
authorization.getToken(function (err, token) {
if (!token) {
console.log('error: ', err);
} else {
// Use your token here
}
});
When I run firebase deploy --only functions I get this error:
Error: Error parsing triggers: Cannot find module 'ibm-watson'
Require stack:
- /Users/TDK/LanguageTwo/functions/index.js
- /Users/TDK/.nvm/versions/node/v13.10.1/lib/node_modules/firebase-tools/lib/triggerParser.js
ibm-watson is installed in my /functions/node_modules directory:
I reinstalled ibm-watson, and for good measure I ran npm install in my functions directory. Plus I ran npm-check and updated all my node modules.
The specific line that causes the error is:
const watson = require('ibm-watson');
When I comment out that line the functions deploy without error. Unfortunately, the function doesn't run. :-)
This line does not cause the deploy error:
const { IamAuthenticator } = require('ibm-watson/auth');
I use IBM Watson in other Firebase Cloud Functions in the same index.js file. These lines from other functions don't cause deploy errors:
let TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
...
var LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
The problem seems to be that requiring the parent directory ibm-watson fails, but requiring the subdirectories of the parent directory works. Any suggestions?
This is as expected. If you take a look at the GitHub repo for ibm-watson - https://github.com/watson-developer-cloud/node-sdk - you will notice that there is no example requiring the top level library. This stops you from pulling in the full library, when you only need to pull in a small sub-component.

{Action name} isn't responding right now. Try again soon

I'm new with the ActionSDK and I created an project with the Action SDK.
The fulfillment of my actions is deploy in Azure as a web service.
I've being updating my action with:
gactions update --action_package action.json --project "projectID"
this being said, the update is successful.
this is my action.json:
{
"actions": [
{
"name": "MAIN",
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"talk to Conduent Helper",
"Talk to conduent help"
]
}
},
"fulfillment": {
"conversationName": "conduentHelpTest"
}
}
],
"conversations": {
"conduentHelpApp": {
"name": "conduentHelpTest",
"url": "https://dialogflowappnc.azurewebsites.net",
"fulfillmentApiVersion": 2
}
}
}
this is a fulfillment code I found after trying my own and had no success with it:
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var exps = express();
const ApiAiApp = require('actions-on-google').ApiAiApp;
exps.use(bodyParser.json());
// API.AI actions
const WELCOME_ACTION = 'input.welcome';
exps.post('/', function(request, response) {
console.log("hello World");
const app = new ApiAiApp({request, response});
function greetUser (app) {
app.tell("Hello World!");
}
let actionMap = new Map();
actionMap.set(WELCOME_ACTION, greetUser);
app.handleRequest(actionMap);
});
exps.listen((process.env.PORT || 7001), function() {
console.log("App up and running, listening.")
})
Whenever I test in the simulator the response is:
{Action name} isn't responding right now. Try again soon.
Whenever I do an update with the command above I see in my web service a request. But when I try to test the action in the simulator I see no request being made.
If someone can point me in the right direction. Point out any knowledge I most gain before proceeding. I there's more info I need to provide let me know and thanks.
Sorry I do not have enough points to comment but We are currently experiencing an outage you can see here if you are being impacted https://azure.microsoft.com/en-us/status/
You will want to monitor the Azure Status Page for further updates. Unfortunately we cannot do anything until the problem has been mitigated by engineering.
There are a couple of potential issues:
First - you haven't shown your package.json file, but the code suggests you're using an older version of the actions-on-google library. So the code itself may not be running. Check your runtime logs to make sure it is.
Next, you've specified that it should be listening on port 7001, but the URL you've provided in the actions.json file doesn't include the port number. If that is the host and port it is running on, and you haven't provided a proxy of some sort, then you need to specify the URL as https://dialogflowappnc.azurewebsites.net:7001/
Also, if you're running on port 7001, you likely haven't opened up the firewall to access it.
But it seems likely you're running a proxy (or you should), since you also need to be providing a valid HTTPS connection with a valid SSL certificate. If this is a self-signed certificate, the connection may still be rejected.

Marklogic 9 + Roxy: can't connect to created database using Node.js

I'm trying out the Roxy deployer. The Roxy app was created using the default app-type. I setup a new ML 9 database, and I ran "ml local bootstrap" using the default ports (8040 and 8041)
Then I setup a node application. I tried the following (sample code from https://docs.marklogic.com/jsdoc/index.html)
var marklogic = require('marklogic');
var conn = {
host: '192.168.33.10',
port: 8040,
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}
var db = marklogic.createDatabaseClient(conn);
db.createCollection(
'/books',
{author: 'Beryl Markham'},
{author: 'WG Sebald'}
)
.result(function(response) {
console.log(JSON.stringify(response, null, 2));
}, function (error) {
console.log(JSON.stringify(error, null, 2));
});
Running the script gave me an error like:
$ node test.js
{
"message": "write document list: cannot process response with 500 status",
"statusCode": 500,
"body": "<error:error xsi:schemaLocation=\"http://marklogic.com/xdmp/error error.xsd\" xmlns:error=\"http://marklogic.com/xdmp/error\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <error:code>XDMP-IMPMODNS</error:code>\n <error:name>err:XQST0059</error:name>\n <error:xquery-version>1.0-ml</error:xquery-version>\n <error:message>Import module namespace mismatch</error:message>\n <error:format-string>XDMP-IMPMODNS: (err:XQST0059) Import module namespace http://marklogic.com/rest-api/endpoints/config does not match target namespace http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED of imported module /MarkLogic/rest-api/endpoints/config.xqy</error:format-string>\n <error:retryable>false</error:retryable>\n <error:expr/>\n <error:data>\n <error:datum>http://marklogic.com/rest-api/endpoints/config</error:datum>\n <error:datum>http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED</error:datum>\n <error:datum>/MarkLogic/rest-api/endpoints/config.xqy</error:datum>\n </error:data>\n <error:stack>\n <error:frame>\n <error:uri>/roxy/lib/rewriter-lib.xqy</error:uri>\n <error:line>5</error:line>\n <error:column>0</error:column>\n <error:xquery-version>1.0-ml</error:xquery-version>\n </error:frame>\n </error:stack>\n</error:error>\n"
}
If I change the port to 8000 (the default appserver that inserts into Documents), the node function executes correctly as expected. I'm not sure if I need to configure anything else with the Roxy-created appserver so that it works with the node.js application.
I'm not sure where the "DELETE_IF_UNUSED" part in the error message is coming from either. There doesn't seem to be any such text in the configuration files generated by Roxy.
Edit: When accessing 192.168.33.10:8040 via the browser, I get a an xml with a similar error:
<error:error xsi:schemaLocation="http://marklogic.com/xdmp/error error.xsd" xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<error:code>XDMP-IMPMODNS</error:code>
<error:name>err:XQST0059</error:name>
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Import module namespace mismatch</error:message>
<error:format-string>XDMP-IMPMODNS: (err:XQST0059) Import module namespace http://marklogic.com/rest-api/endpoints/config does not match target namespace http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED of imported module /MarkLogic/rest-api/endpoints/config.xqy</error:format-string>
<error:retryable>false</error:retryable>
<error:expr/>
<error:data>
<error:datum>http://marklogic.com/rest-api/endpoints/config</error:datum>
<error:datum>http://marklogic.com/rest-api/endpoints/config_DELETE_IF_UNUSED</error:datum>
<error:datum>/MarkLogic/rest-api/endpoints/config.xqy</error:datum>
</error:data>
<error:stack>
<error:frame>
<error:uri>/roxy/lib/rewriter-lib.xqy</error:uri>
<error:line>5</error:line>
<error:column>0</error:column>
<error:xquery-version>1.0-ml</error:xquery-version>
</error:frame>
</error:stack>
</error:error>
If it matters, MarkLogic version is 9.0-3.1. It's a fresh install too.
Any advice?
Based on the comments, it looks like the problem is that the Node.js Client API expects to talk to a REST API endpoint, but the default Roxy configuration is an MVC application. If you haven't already done anything major with your Roxy app, I'd remove it and create one with --app-type=rest.
$ ml new my-app --app-type=rest --server-version=9
$ ml local bootstrap
$ ml local deploy modules
Then try your Node app.

azure node.js console.log not logging into stdout or stderr files

I have a node.js app in azure (app service). The node.js is using the following modules
"scripts": {
"start": "node bin\/www",
"test": "mocha"
},
"dependencies": {
"async": "^1.5.2",
"bluebird": "^3.3.4",
"express": "^4.13.3",
"ioredis": "^1.15.1",
"lodash": "^4.6.1",
"socket.io": "^1.4.5"
},
"devDependencies": {
"chai": "^3.5.0",
"socket.io-client": "^1.4.5"
}
I wanted to enable the logging of app so i set the environment variable DEBUG = * using the portal->configure->app settings. since then, the app's express and socketio logs started to appear in /LogFiles/Application folder with cryptic name xxxxxx-nnnn-stderr-nnnnnnnnnnnnnn.txt
I added a console.log statement in one of the files in my app's lib folder
function MessageActions(redis, io) {
...
}
MessageActions.prototype.routeMessage = function(message) {
console.log('routeMessage: ' + JSON.stringify(message)); //this is not appearing anywhere in logs
var self = this;
return Promise.join(
self.checkUserMessage(message),
self.checkGroupMessage(message),
function(sendtarget, sendgroup) {
if(!sendtarget && !sendgroup) {
var pmsg = util.inspect(message);
throw new Error('Failed to route message: ' + pmsg);
}
}
);
}
I am sure that this function is being called as i could see the below error in the stderr file
[Error: Failed to route message: { ... }]
But i am not able to find the log statement added with console.log anywhere in this stderr file. also, there is no stdout file in the /LogFiles/Application folder.
How to add a log statement and where to check for it?
My IISNode.yml file has the following two lines
loggingEnabled: true
devErrorsEnabled: true
Please try to set the Application Logging (Filesystem) to on to enable the streaming log feature.
After that, you will find several logs files in /LogFiles/Application folder with cryptic name xxxxxx-nnnn-stdout-nnnnnnnnnnnnnn.txt which contain the output of your console.log().
But please notice the description:
Enable application logging to collect diagnostic traces from your web app code. You'll need to turn this on to enable the streaming log feature. This setting turns itself off after 12 hours.
To keep a persistence logging files in Node.js applications, you can use some node.js logging libraries like winston.
There is a way to see the console output live if you take the following steps:
Open website blade in Azure portal
Click on the tools icon
Click on the "Visual Studio Online" tool
Toggle the tool to "On"
...wait while the extension is enabled
Click the "Go->" icon under the tool toggle.
Once Visual Studio Online "Monaco" window is up, you can "Run" your application which should show your website in another window, but your "Monaco" window will have the console output from your application.
Hope this helps find your problem.
In your Index.js/Messages , replace the following code:
if (useEmulator) {
var restify = require('restify');
var server = restify.createServer();
server.listen(3978, function() {
console.log('test bot endpoint at http://localhost:3978/api/messages');
});
server.post('/api/messages', connector.listen());
}
else {
module.exports = { default: connector.listen() }
}
with:
if (useEmulator) {
var restify = require('restify');
var server = restify.createServer();
server.listen(3978, function() {
console.log('test bot endpoint at http://localhost:3978/api/messages');
});
server.post('/api/messages', connector.listen());
}
else {
var listener = connector.listen();
var withLogging = function(context, req) {
console.log = context.log;
listener(context, req);
}
module.exports = { default: withLogging }
}
This will override the console.log function. Hope , this will help.

phonegap webos 3.0+

I have a phonegap iOS app that i ported to webos on the touchpad the app works great except for the one iOS plugin that i used. it basically saved the canvas data to the photo roll. From my understanding of webos i will need to create a node.js service and write the data to a buffer and finally to the file system, there is an example for that in the forums. however what i can not figure out is how to call all of this from my phonegap app. I believe i will need to have the following in my index.html file.
<script src="/opt/PalmSDK/Current/share/framework/enyo/1.0/framework/enyo.js" type="text/javascript"></script>
and something like
enyo.create({kind: "Main"}).renderInto(document.body);
my guess i will also have to have all of the "kind" data in a js file. but how do i do the little step from my app's js file to communicate with the service that is created. I looked in the phonegap 1.0.js file and see that they are calling services this way.
this.service = navigator.service.Request('palm://com.palm.applicationManager', {
method: 'launch',
parameters: {
id: 'com.palm.app.camera',
params: {
appId: 'com.palm.app.camera',
name: 'capture',
sublaunch: true,
filename: filename
}
},
onSuccess: successCallback,
onFailure: errorCallback
});
but i also noticed it appears that it is all mojo and what i am doing is enyo, so yes i am pretty confused the moment...
seems it should be easy to call a service in webos, say here is a string of image data and write it to the file system from my existing phonegap app. and not have to do everything in enyo. anyone have a sample of a webos plugin like this or know where to point me?
thanks tim
**Update
I have created a node service now as defined below, i think that works and i am trying to make the call to the service, but it does not get to it. the test app runs on my touchpad, but when i push the button to save the image i do not get into the service. I tried to follow what was done for the camera in the phonegap0.0.1.js file this is a copy of my service, how i defined it and how i am calling it. any ideas what i am doing wrong.
services.json =
"id": "com.tim.pgmojo1.service",
"description": "FileIO Service",
"services": [
{
"name": "com.tim.pgmojo1.service",
"description": "FileIO Service",
"commands": [
{
"name": "writefile",
"assistant": "WriteFileAssistant",
"public": true
}]
}]
}
** service code
var libraries = MojoLoader.require({ name: "foundations", version: "1.0" });
var fs = IMPORTS.require("fs");
var sys = require('sys');
var WriteFileAssistant = function() {}
WriteFileAssistant.prototype.run = function(future) {
var mypath = this.controller.args.thepath;
var mydata = this.controller.args.thedata;
console.log("in write file");
console.log("path=" + thepath);
console.log("image data=" + thedata);
var data = content.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
fs.writeFile('/media/internal/downloads/timimage.png', buf);
}
my call to the service**
this.service = navigator.service.Request('palm://com.tim.pgmojo.service', {
method: 'writefile',
parameters: {
thepath: '/media/internal/downloads/timimage.png',
thedata: canvasData
},
onSuccess: mySuccess,
onFailure: myFailure
});
currently i have this in my index.html file since it is only for testing..
Mojo is still included on the TouchPad. You can use the same service-calling functions as PhoneGap is doing.
In Enyo, access to on-device services is handled by the enyo.PalmService kind. You can see an example of an app that has a node.js service included and how calls are made to this service at https://github.com/palm/txjs-fortunecookie

Resources