0

I'am currently in the first steps of programming a small Circuit Bot with Node.js.

Here's what I got so far:

const Circuit = require('../node_modules/circuit-sdk/circuit.js'); //Circuit-Library importieren
var config = require('./config.json'); //Configs für Bot
console.log(config); // Configs ausgeben
var client = null;


client = new Circuit.Client({
  client_id: config.client_id,
  client_secret: config.client_secret
});
client.logon()
  .then(user => console.log('Logged on'))

But the client can not log in due to a thrown TypeError:

TypeError: XMLHttpRequest is not a constructor
    at /home/jovyan/node_modules/circuit-sdk/circuit.js:59768:37
    at new Promise (<anonymous>)
    at xhr (/home/jovyan/node_modules/circuit-sdk/circuit.js:59767:20)
    at /home/jovyan/node_modules/circuit-sdk/circuit.js:60283:17
    at new Promise (<anonymous>)
    at authenticateClientCredentials (/home/jovyan/node_modules/circuit-sdk/circuit.js:60282:20)
    at Object.circuit.Client._self.logon (/home/jovyan/node_modules/circuit-sdk/circuit.js:63899:24)
    at evalmachine.<anonymous>:5:8
    at Script.runInThisContext (vm.js:116:20)
    at Object.runInThisContext (vm.js:306:38)

I tried every possible combination with the authentification parameters e.g. declaring them with the object or trying to push them with the logon function.

1 Answers1

0

For a regular node app the Circuit SDK is included like this:

const Circuit = require('circuit-sdk');

This will load the Circuit Node SDK which implements a few browser specific APIs such as XMLHttpRequest.

The only case you would want to require the regular browser based Circuit JS SDK in a node app would be in an electron renderer process (which essentially is a Chromium browser). In that special case you would include like this:

const Circuit = require('circuit-sdk/circuit.js');

See the updated node-sdk-example app as a good starting point for a node app (bot). https://github.com/circuit/node-sdk-example

Roger Urscheler
  • 774
  • 2
  • 6
  • 11