首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GUPSHUP和nodejs向电话号码发送sms

使用GUPSHUP和nodejs向电话号码发送sms
EN

Stack Overflow用户
提问于 2022-03-03 08:24:12
回答 1查看 500关注 0票数 0

我需要帮助发送短信给用户使用nodejs和Gupshup.io。我很难理解他们的文档。

EN

回答 1

Stack Overflow用户

发布于 2022-03-07 17:51:39

库拉姆·沙赫扎德

我是Gupshup的聊天机器人开发人员,请让我知道你不明白什么。

无论哪种方式,这里我都将分享代码片段,以便在node.js中使用我们的API发送短信。

代码语言:javascript
复制
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
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71334033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档