0

I want to implement SMS verification on a Node.js Server that when I am sending request to a URL with user phone number I could send verification SMS to that phone number, I read the documentation here and still, there is an error when I want to import sinch to my app like codes below

const express        = require('express');
const bodyParser     = require('body-parser');
const app            = express();
const PORT = process.env.PORT || 5000;
const path = require('path');
const fetch = require('node-fetch');
var APPLICATION_KEY = 'MYAPP_KEY' ;
var SinchClient = require('sinch-rtc');

var sinchClient = new SinchClient({
    applicationKey: APPLICATION_KEY,
    capabilities: {messaging: true},
    onLogMessage: function(message) {
        console.log(message);
    }
});

sinchClient.start(CREDENTIALS).then(function() {
        console.log('Success!');
    })




app.use( bodyParser.json() );      // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
  extended: true
}));


app.use(express.static(path.join(__dirname, 'public')))
  .set('views', path.join(__dirname, 'views'))
  .set('view engine', 'ejs')
  .get('/', (req, res) => res.render('pages/index'))
  .get('/test', (req, res) => {
    //mycodes to verify phone number


  })
.listen(PORT, () => console.log(`Listening on ${ PORT }`));

it will give me this error

(function (exports, require, module, __filename, __dirname)
{ function Notification(e,t,i,n){this.progress=e/t,this.message=i,this.object=n}function getBrowserInfo(){var e,t=navigator.userAgent,i=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||t.match(/(applewebkit(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(i[1])?"IE "+((e=/\brv[ :]+(\d+)/g.exec(t)||[])[1]||""):"Chrome"===i[1]&&null!=(e=t.match(/\bOPR\/(\d+)/))?"Opera "+e[1]:(i=i[2]?[i[1],i[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=t.match(/version\/(\d+)/i))&&i.splice(1,1,e[1]),i.join("/").substring(0,50))}function getPlatformInfo(){return navigator.platform}
function Sinch(e){if(!e)throw new TypeError("Could not create SinchClient, configuration not provided.");if(e.capabilities=e.capabilities||{},"string"!=typeof e.applicationKey)throw new TypeError("Could not create SinchClient, applicationKey is not a string");this.c

TypeError: Cannot read property 'indexOf' of undefined
    at new Sinch (C:\Users\user\project\node_modules\sinch-rtc\lib\sinch.node.min.js:1:1741)
    at Object.<anonymous> (C:\Users\user\project\server.js:9:13)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Thanks in Advance

Martin
  • 429
  • 3
  • 18

1 Answers1

0

To send sms you should not set messaging to to true, in fact i would use this for node https://www.npmjs.com/package/sinch-verification

cjensen
  • 2,703
  • 1
  • 16
  • 15
  • error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "12.0", "14.0", "4.0". gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Users\Shoaib\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:285:23) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) I faced this error can you help me @cjensen? – Martin Feb 22 '18 at 06:05