我需要帮助使用 nodejs 和 Gupshup.io 向用户发送短信。我很难理解他们的文档。
库拉姆·沙赫扎德
我是 Gupshup 的聊天机器人开发人员,有什么不明白的地方请告诉我。
无论哪种方式,我都会在这里分享使用我们的API在node.js中发送短信的snipet代码。
const { default: axios } = require('axios');
/*
Variables to replace
YOUR_API_KEY => The unique identifier for a Gupshup account.
YOUR_APP_ID=> The unique identifier for an app. An app's appid can be found in the cURL request generated on the dashboard.
*/
const sendMessage = (msg, phone, callbackFunc) => {
const params = new URLSearchParams()
params.append('destination', phone);
params.append('message', msg);
params.append('source', 'GSDSMS'); //Required only for india
const config = {
headers: {
'apikey': YOUR_API_KEY,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios.post('http://api.gupshup.io/sms/v1/message/:YOUR_APP_ID', params, config)
.then((result) => {
console.log('Message sent');
callbackFunc(result.data);
})
.catch((err) => {
console.log(err);
callbackFunc(err);
})
}
module.exports = {
sendMessage
}
我想使用 sms gupshup 发送 Whatsapp 消息 节点js