Skip to content

Instantly share code, notes, and snippets.

@hy3
Last active November 17, 2020 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hy3/a0b8437ac2f25c376bba8b6b6e87d9fd to your computer and use it in GitHub Desktop.
Save hy3/a0b8437ac2f25c376bba8b6b6e87d9fd to your computer and use it in GitHub Desktop.
Sample to invoke Kompira Pigeon by AWS Lambda
const https = require('https');
const invokePigeon = (callflowId, guidanceId, parameters) => new Promise((resolve, reject) => {
const options = {
host: 'xxx.cloud.kompira.jp', // replace to your space domain
port: 443,
path: '/api/apps/pigeon/chain/invoke',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Authorization': 'Token XXXXXX' // replace XXXXXX to your API Token
}
};
const payload = {
params: {
callflowId: callflowId,
guidanceId: guidanceId,
parameters: parameters
}
};
const req = https.request(options, res => {
let buffer = "";
res.on('data', chunk => buffer += chunk);
res.on('end', () => resolve(JSON.parse(buffer)));
});
req.on('error', e => reject(e.message));
req.write(JSON.stringify(payload));
req.end();
});
exports.handler = async (event, context) => new Promise( async (resolve, reject) => {
const callflowId = '00000000-0000-0000-0000-0000000000000'; // replace to your callflow ID
const guidanceId = '00000000-0000-0000-0000-0000000000000'; // replace to your guidance ID
const parameters = {
server: 'test',
level: 'error'
}; // This is parameter sample. Please change it to suit your guidance template.
const response = await invokePigeon(callflowId, guidanceId, parameters);
console.log('Pigeon response:\n' + JSON.stringify(response));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment