如何从变量配置 web-hook 端点?
How to config web-hook endpoint from a variable?
我想根据变量中的值来控制我的 webhook 端点的选择。我有我的钩子和逻辑,但我找不到一种方法来控制如何选择 select 的端点。我想根据 'NumOfClassesBooked' 的值从三个不同的端点中进行选择。这可能吗?提前致谢。
var post_options = {
hostname: 'webhook.site',
path: '/fc6d1598-268d-4cd0-8e26-e65f7a5b859b',
method: 'POST',
headers: {
'Content-Type': 'text/json'
}
};
// Set up the request
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// post the data
post_req.write(post_data);
post_req.end();
//choose endpoint
function whichHookToSendTo(NumOfClassesBooked) {
if (NumOfClassesBooked == "1") { }
else if (NumOfClassesBooked == "4") { }
else if (NumOfClassesBooked == "8") { }
}
您可以保留 url 和 numOfClassesBooked 的地图:
const webhooks = {
1':' 'url_one',
2':' 'url_two',
...
}
然后使用numOfClassesBooked变量select右边url:
const url = webhooks[numOfClassesBooked]
// post the data
post_data.path = url
post_req.write(post_data);
post_req.end();
我想根据变量中的值来控制我的 webhook 端点的选择。我有我的钩子和逻辑,但我找不到一种方法来控制如何选择 select 的端点。我想根据 'NumOfClassesBooked' 的值从三个不同的端点中进行选择。这可能吗?提前致谢。
var post_options = {
hostname: 'webhook.site',
path: '/fc6d1598-268d-4cd0-8e26-e65f7a5b859b',
method: 'POST',
headers: {
'Content-Type': 'text/json'
}
};
// Set up the request
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
// post the data
post_req.write(post_data);
post_req.end();
//choose endpoint
function whichHookToSendTo(NumOfClassesBooked) {
if (NumOfClassesBooked == "1") { }
else if (NumOfClassesBooked == "4") { }
else if (NumOfClassesBooked == "8") { }
}
您可以保留 url 和 numOfClassesBooked 的地图:
const webhooks = {
1':' 'url_one',
2':' 'url_two',
...
}
然后使用numOfClassesBooked变量select右边url:
const url = webhooks[numOfClassesBooked]
// post the data
post_data.path = url
post_req.write(post_data);
post_req.end();