fix(placetel): Parse request body inside of run method

This commit is contained in:
Faruk AYDIN
2023-10-11 11:17:19 +02:00
parent 53189a6487
commit 7615e62bbc
3 changed files with 21 additions and 2 deletions

View File

@@ -73,6 +73,7 @@
"pg": "^8.7.1",
"php-serialize": "^4.0.2",
"pluralize": "^8.0.0",
"raw-body": "^2.5.2",
"showdown": "^2.1.0",
"stripe": "^11.13.0",
"winston": "^3.7.1",

View File

@@ -1,6 +1,7 @@
import Crypto from 'crypto';
import { IJSONObject } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import getRawBody from 'raw-body';
export default defineTrigger({
name: 'Hungup Call',
@@ -68,6 +69,13 @@ export default defineTrigger({
],
async run($) {
const stringBody = await getRawBody($.request, {
length: $.request.headers['content-length'],
encoding: true,
});
const jsonRequestBody = JSON.parse(stringBody);
let types = ($.step.parameters.types as IJSONObject[]).map(
(type) => type.type
);
@@ -76,9 +84,9 @@ export default defineTrigger({
types = ['all'];
}
if (types.includes($.request.body.type) || types.includes('all')) {
if (types.includes(jsonRequestBody.type) || types.includes('all')) {
const dataItem = {
raw: $.request.body,
raw: jsonRequestBody,
meta: {
internalId: Crypto.randomUUID(),
},