Skip to content
Snippets Groups Projects
Commit b8a15207 authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

fix: add topic type to each webhook

parent 85e6e98a
No related branches found
No related tags found
1 merge request!72fix: add topic type to each webhook
Pipeline #69902 passed with stage
in 2 minutes and 14 seconds
...@@ -599,10 +599,10 @@ export const attachDidWebHandler = ( ...@@ -599,10 +599,10 @@ export const attachDidWebHandler = (
} }
}); });
}; };
export const webHookHandler = async <T>(
export const webHookHandler = async (
addr: string, addr: string,
ev: TrustPingResponseReceivedEvent, webHookTopic: string,
payload: T,
) => { ) => {
const promises: Promise<AxiosResponse>[] = []; const promises: Promise<AxiosResponse>[] = [];
...@@ -611,18 +611,11 @@ export const webHookHandler = async ( ...@@ -611,18 +611,11 @@ export const webHookHandler = async (
for (const pair of tokenUrlPairs) { for (const pair of tokenUrlPairs) {
const [token, url] = pair.split("@"); const [token, url] = pair.split("@");
const promise = axios.post( const promise = axios.post(`${url}/topic/${webHookTopic}`, payload, {
url, headers: {
{ "X-Api-Key": token,
thid: ev.payload.message.threadId,
connectionId: ev.payload.connectionRecord.id,
}, },
{ });
headers: {
"X-Api-Key": token,
},
},
);
promises.push(promise); promises.push(promise);
} }
...@@ -634,10 +627,10 @@ export const webHookHandler = async ( ...@@ -634,10 +627,10 @@ export const webHookHandler = async (
if (promiseResult.status === "rejected") { if (promiseResult.status === "rejected") {
console.log( console.log(
`Failed to send web hook to ${url}. Reason ${promiseResult.reason}`, `Failed to send web hook to ${url}/topic/${webHookTopic}. Reason ${promiseResult.reason}`,
); );
continue; continue;
} }
console.log(`Successfully sent web hook to ${url}`); console.log(`Successfully sent web hook to ${url}/topic/${webHookTopic}`);
} }
}; };
...@@ -73,7 +73,10 @@ export class AgentEventListenerService implements OnModuleInit { ...@@ -73,7 +73,10 @@ export class AgentEventListenerService implements OnModuleInit {
throw new Error("Agent config is missing agentWebHook"); throw new Error("Agent config is missing agentWebHook");
} }
return webHookHandler(this.agentConfig?.agentWebHook, ev); return webHookHandler(this.agentConfig?.agentWebHook, "ping", {
thid: ev.payload.message.threadId,
connectionId: ev.payload.connectionRecord.id,
});
}, },
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment