首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GUPSHUP发送带有附件的模板消息

GUPSHUP发送带有附件的模板消息
EN

Stack Overflow用户
提问于 2022-06-20 20:36:12
回答 1查看 148关注 0票数 1

我试图通过gupshup使用统一的单发送消息API端点https://api.gupshup.io/sm/api/v1/msg发送模板消息。

我们有一个模板消息,其中有相关的措辞,并规定应该有一个附件。当我们尝试发送附件时,它在以下消息中失败,(1005)消息发送失败,因为用户对会话消息不活跃,模板不匹配

在编码了JSON的message元素中,我尝试了几个选项,它们都拒绝使用上面相同的消息。

代码语言:javascript
运行
复制
innerJson = { "isHSM": "true", "type": "file", "url": fileURL + location, "filename": filename, "text": message }
innerJson = { "isHSM": "true", "type": "file", "url": fileURL + location, "filename": filename, "caption": message }
innerJson = { "type": "file", "url": fileURL + location, "filename": filename, "text": message }
innerJson = {  "type": "file", "url": fileURL + location, "filename": filename, "caption": message }

在gupshup文档中找不到任何关于如何这样做的显式示例。

EN

回答 1

Stack Overflow用户

发布于 2022-06-29 18:23:08

我向您发送一个具有正确端点的链接,用于发送模板。

这里还有一个如何在node.js中使用它的示例:

代码语言:javascript
运行
复制
const sendTemplateWhatsapp = (templateId, phone, media, callbackFunc) => {
    innerJson = { "type":"file","url":"your_url" }
    const params = new URLSearchParams()
    params.append('channel', 'whatsapp');
    params.append('source', waba_number);
    params.append('destination', phone);
    params.append('src.name', waba_name);
    params.append('template', templateId);
    params.append('message', JSON.stringify(innerJson));

    const config = {
        headers: {
            'apikey': 'your_apikey',
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }

    axios.post('http://api.gupshup.io/sm/api/v1/template/msg', params, config)
        .then((result) => {
            console.log('Template sent to whatsapp');
            callbackFunc(result.data);
        })
        .catch((err) => {
            console.log(err);
            callbackFunc(err);
        })
}

希望这能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72692704

复制
相关文章

相似问题

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