diff --git a/libs/askar/src/agent.utils.ts b/libs/askar/src/agent.utils.ts index c7cf78055dbb16913487b18e30e0500e111c71e3..3ae64575daede064147e0c2bd3192df2c9067620 100644 --- a/libs/askar/src/agent.utils.ts +++ b/libs/askar/src/agent.utils.ts @@ -52,7 +52,7 @@ import { AskarModule } from "@aries-framework/askar"; import { ariesAskar } from "@hyperledger/aries-askar-nodejs"; import { Key as AskarKey, KeyAlgs } from "@hyperledger/aries-askar-shared"; import { IConfAgent } from "@ocm-engine/config"; -import axios from "axios"; +import axios, { AxiosResponse } from "axios"; import { catchError, filter, @@ -604,13 +604,40 @@ export const webHookHandler = async ( addr: string, ev: TrustPingResponseReceivedEvent, ) => { - try { - await axios.post(addr, { - thid: ev.payload.message.threadId, - connectionId: ev.payload.connectionRecord.id, - }); - } catch (e) { - console.log("Error sending webhook"); - console.log(JSON.stringify(e, null, 2)); + const promises: Promise<AxiosResponse>[] = []; + + const tokenUrlPairs = addr.split(";"); + + 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, + }, + { + headers: { + "X-Api-Key": token, + }, + }, + ); + + promises.push(promise); + } + + const promiseResults = await Promise.allSettled(promises); + for (let index = 0; index < promiseResults.length; index++) { + const promiseResult = promiseResults[index]; + const [_, url] = tokenUrlPairs[index].split("@"); + + if (promiseResult.status === "rejected") { + console.log( + `Failed to send web hook to ${url}. Reason ${promiseResult.reason}`, + ); + continue; + } + console.log(`Successfully sent web hook to ${url}`); } };