简体   繁体   中英

SMS verification using sinch and node.js server

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

要发送短信,您不应将消息传递设置为true,实际上,我会将其用于节点https://www.npmjs.com/package/sinch-verification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM