Skip to content

Commit

Permalink
Merge pull request #632 from Portkey-AI/fix/webhook-plugin-header-par…
Browse files Browse the repository at this point in the history
…sing

webhook plugin header parsing logic to allow objects
  • Loading branch information
VisargD authored Sep 27, 2024
2 parents 6798bdf + eee36eb commit 8ae3ff6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugins/default/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { PluginContext, PluginHandler, PluginParameters } from '../types';
import { post } from '../utils';

function parseHeaders(headers: unknown): Record<string, string> {
if (typeof headers === 'object' && headers !== null) {
return headers as Record<string, string>;
}
if (typeof headers === 'string') {
return JSON.parse(headers);
}
return {};
}

export const handler: PluginHandler = async (
context: PluginContext,
parameters: PluginParameters
) => {
let error = null;
let verdict = false;
let data = null;

try {
let url = parameters.webhookURL;
let headers: Record<string, string> = parameters?.headers
? JSON.parse(parameters.headers)
: {};
const headers = parseHeaders(parameters.headers);
({ verdict, data } = await post(url, context, { headers }, 3000));
} catch (e: any) {
delete e.stack;
Expand Down

0 comments on commit 8ae3ff6

Please sign in to comment.