Skip to content

Commit 3c28891

Browse files
committed
fix(api): validate WhatsApp credentials at runtime instead of non-null assertions
The credential fields (appSecret, verifyToken) are intentionally optional in the shared config since existing outbound-only integrations don't need them. Add an explicit guard in buildAdapters() that throws a clear error when the agent adapter is created without the required fields. Made-with: Cursor
1 parent ab3ebcb commit 3c28891

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

apps/api/src/app/agents/services/chat-sdk.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,20 @@ export class ChatSdkService implements OnModuleDestroy {
245245
};
246246
}
247247
case AgentPlatformEnum.WHATSAPP: {
248+
if (!credentials.apiToken || !credentials.secretKey || !credentials.token || !credentials.phoneNumberIdentification) {
249+
throw new BadRequestException(
250+
'WhatsApp agent integration requires accessToken, appSecret, verifyToken, and phoneNumberId credentials'
251+
);
252+
}
253+
248254
const { createWhatsAppAdapter } = await esmImport('@chat-adapter/whatsapp');
249255

250256
return {
251257
whatsapp: createWhatsAppAdapter({
252-
accessToken: credentials.apiToken!,
253-
appSecret: credentials.secretKey!,
254-
verifyToken: credentials.token!,
255-
phoneNumberId: credentials.phoneNumberIdentification!,
258+
accessToken: credentials.apiToken,
259+
appSecret: credentials.secretKey,
260+
verifyToken: credentials.token,
261+
phoneNumberId: credentials.phoneNumberIdentification,
256262
}),
257263
};
258264
}

0 commit comments

Comments
 (0)