【发布时间】:2021-12-05 04:27:43
【问题描述】:
我正在尝试向 twilio 发出 GET 请求以从特定渠道获取数据,之后我需要对其进行一些更改,然后再次发布。
我是全新的 js 工作人员,我将不胜感激任何建议 我没有使用 Twilio SDK
到目前为止,我做了这个..但它没有发出帖子请求
function modifyChannel(sid, json) {
console.log(json);
return new Promise((resolve, reject) => {
let newJson = JSON.parse(json.attributes);
newJson.task_sid = null;
json.attributes = JSON.stringify(newJson);
resolve(json);
})
}
function postChannel(sid, json) {
axios({
method: 'post',
url:`https://chat.twilio.com/v2/Services/${DEV_CREDENTIAL.programmableChatSid}/Channels/${sid}`,
auth: {
username: DEV_CREDENTIAL.account,
password: DEV_CREDENTIAL.token
},
data: {
json
}
});
}
axios({
method: 'get',
url:`https://chat.twilio.com/v2/Services/${DEV_CREDENTIAL.programmableChatSid}/Channels/${channel_sid}`,
auth: {
username: DEV_CREDENTIAL.account,
password: DEV_CREDENTIAL.token
}
})
.then(response => {
return modifyChannel(channel_sid, response.data);
}).then(jsonModified => { postChannel(channel_sid, jsonModified); })
.catch(err => console.log(err));
【问题讨论】:
标签: javascript axios request twilio