javascript - 通过 GupShup 发送图像
问题描述
尝试通过 GupShup 发送图像。我正在使用他们的沙箱。我的后端是带有feathersjs 的node.js。但它返回给我这个错误:
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: [ReadableState],
readable: true,
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: true,
_transformState: [Object],
[Symbol(kCapture)]: false
},
disturbed: false,
error: null
},
[Symbol(Response internals)]: {
url: 'https://api.gupshup.io/sm/api/v1/msg',
status: 400,
statusText: 'Bad Request',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
}
这是发送图像的代码
const form = new URLSearchParams();
form.append('channel', 'whatsapp');
form.append('destination', destination);
form.append('source', app.get('GUPSHUP_NUMBER'));
form.append('message.payload', JSON.stringify(message));
form.append('src.name', 'OneAccess');
console.log(form);
try {
const res = await fetch('https://api.gupshup.io/sm/api/v1/msg', {
method: 'POST',
body: form,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
apikey: app.get('GUPSHUP_API'),
},
});
console.log('result message', res);
} catch (err) {
console.log('errro sending msg', err);
}
这是我要发送的信息
message: {
type: 'image',
originalUrl:
'https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg',
previewUrl:
'https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg',
caption: 'Sample image',
},
谁能帮我?
解决方案
将message.payload更改为message。您可以在https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation#SendImage检查正确的签名
推荐阅读
- dart - 根据滑块值设置文本值
- php - PHP中的“致命错误:无法在写入上下文中使用函数返回值”
- angular - 如何通过表单控件验证输入类型=时间的字段?使用角材料
- javascript - 在 Atom 编辑器中突出显示 HTML 中的 javascript
- python-3.x - 有没有办法将列表 A 中的数字添加到列表 B 中相应位置的数字中?
- excel - 按公式值分组行
- java - 将数组数据存储在 Java 9 文本输出/输入的文件中
- go - 如果通过 os.exec 运行,调用的程序会失败
- html - 用于分组的语义正确的 HTML5
- java - 如何从firebase数据库检索经纬度到android地图应用程序