feat(placetel): Add types to hungup call trigger

This commit is contained in:
Faruk AYDIN
2023-10-09 12:49:59 +02:00
parent 265d57d8b7
commit b59840cb77

View File

@@ -8,6 +8,35 @@ export default defineTrigger({
type: 'webhook', type: 'webhook',
description: 'Triggers when a call is hungup.', description: 'Triggers when a call is hungup.',
arguments: [ arguments: [
{
label: 'Types',
key: 'types',
type: 'dynamic' as const,
required: false,
description: '',
fields: [
{
label: 'Type',
key: 'type',
type: 'dropdown' as const,
required: true,
description:
'Filter events by type. If the types are not specified, all types will be notified.',
variables: true,
options: [
{ label: 'All', value: 'all' },
{ label: 'Voicemail', value: 'voicemail' },
{ label: 'Missed', value: 'missed' },
{ label: 'Blocked', value: 'blocked' },
{ label: 'Accepted', value: 'accepted' },
{ label: 'Busy', value: 'busy' },
{ label: 'Cancelled', value: 'cancelled' },
{ label: 'Unavailable', value: 'unavailable' },
{ label: 'Congestion', value: 'congestion' },
],
},
],
},
{ {
label: 'Numbers', label: 'Numbers',
key: 'numbers', key: 'numbers',
@@ -39,6 +68,15 @@ export default defineTrigger({
], ],
async run($) { async run($) {
let types = ($.step.parameters.types as IJSONObject[]).map(
(type) => type.type
);
if (types.length === 0) {
types = ['all'];
}
if (types.includes($.request.body.type) || types.includes('all')) {
const dataItem = { const dataItem = {
raw: $.request.body, raw: $.request.body,
meta: { meta: {
@@ -47,31 +85,29 @@ export default defineTrigger({
}; };
$.pushTriggerItem(dataItem); $.pushTriggerItem(dataItem);
}
}, },
async testRun($) { async testRun($) {
const response = await $.http.get('/v2/calls?order=desc'); const types = ($.step.parameters.types as IJSONObject[]).map(
(type) => type.type
);
if (!response?.data) { const sampleEventData = {
return; type: types[0] || 'missed',
} duration: 0,
from: '01662223344',
const lastCall = response.data[0]; to: '02229997766',
call_id:
const computedWebhookEvent = { '9c81d4776d3977d920a558cbd4f0950b168e32bd4b5cc141a85b6ed3aa530107',
type: lastCall.type,
duration: lastCall.duration,
from: lastCall.from_number,
to: lastCall.to_number.number.number,
call_id: lastCall.id.toString(),
event: 'HungUp', event: 'HungUp',
direction: 'in', direction: 'in',
}; };
const dataItem = { const dataItem = {
raw: computedWebhookEvent, raw: sampleEventData,
meta: { meta: {
internalId: computedWebhookEvent.call_id.toString(), internalId: sampleEventData.call_id.toString(),
}, },
}; };