diff --git a/libs/askar/src/agent.utils.ts b/libs/askar/src/agent.utils.ts index 3ae64575daede064147e0c2bd3192df2c9067620..2bd89628296e027edbe67c245d5eda792fe50157 100644 --- a/libs/askar/src/agent.utils.ts +++ b/libs/askar/src/agent.utils.ts @@ -599,10 +599,10 @@ export const attachDidWebHandler = ( } }); }; - -export const webHookHandler = async ( +export const webHookHandler = async <T>( addr: string, - ev: TrustPingResponseReceivedEvent, + webHookTopic: string, + payload: T, ) => { const promises: Promise<AxiosResponse>[] = []; @@ -611,18 +611,11 @@ export const webHookHandler = async ( for (const pair of tokenUrlPairs) { const [token, url] = pair.split("@"); - const promise = axios.post( - url, - { - thid: ev.payload.message.threadId, - connectionId: ev.payload.connectionRecord.id, + const promise = axios.post(`${url}/topic/${webHookTopic}`, payload, { + headers: { + "X-Api-Key": token, }, - { - headers: { - "X-Api-Key": token, - }, - }, - ); + }); promises.push(promise); } @@ -634,10 +627,10 @@ export const webHookHandler = async ( if (promiseResult.status === "rejected") { 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; } - console.log(`Successfully sent web hook to ${url}`); + console.log(`Successfully sent web hook to ${url}/topic/${webHookTopic}`); } }; diff --git a/libs/askar/src/askar/agent-event-listener.service.ts b/libs/askar/src/askar/agent-event-listener.service.ts index 6ac3e2c47e631e7a1324252c6c57b9dfe5be0ada..e643b4dbec1f13f7bd38e755a28db912edcc6303 100644 --- a/libs/askar/src/askar/agent-event-listener.service.ts +++ b/libs/askar/src/askar/agent-event-listener.service.ts @@ -73,7 +73,10 @@ export class AgentEventListenerService implements OnModuleInit { 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, + }); }, ); }