我有一个场景,我需要通过我的应用程序发送短信,因为我正在使用textbelt api服务但它给我的错误说不能读取属性'未定义的长度'
我正在使用express.js框架
控制器代码:
var text = require('textbelt');
exports.sendSms = function(req, res) {
var opts = {
fromAddr: 'sthakur@innominds.com', // "from" address in received text
fromName: 'shikha', // "from" name in received text
region: 'india', // region the receiving number is in: 'us', 'canada', 'intl'
subject: 'something' // subject of the message
}
text.sendText('9032400119', 'A sample text message!',opts);
};
和路由部分:
'use strict';
var express = require('express');
var controller = require('./sms.controller');
router.get('/', controller.index);
router.get('/sendSms', controller.sendSms);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
module.exports = router;
我不知道为什么会出现这个错误
任何帮助都非常感谢
答案 0 :(得分:-2)
<强>更新强>
我试过给我们区域,我得到了日志
这是我试过的,我的控制台上有“短信发送”日志,但短信没有发送。
var opts = {
fromAddr: '%s@email.uscc.net', // "from" address in received text
fromName: 'User', // "from" name in received text
region: 'us', // region the receiving number is in: 'us', 'canada', 'intl'
subject: 'Test SMS' // subject of the message
}
text.sendText('82*****', 'A sample text message!', opts);
console.log(opts)
console.log('SMS SENT')