|
1 | 1 | import { createHmac, timingSafeEqual } from "node:crypto"; |
2 | | -import { extractCard, ValidationError } from "@chat-adapter/shared"; |
| 2 | +import { |
| 3 | + AdapterError, |
| 4 | + extractCard, |
| 5 | + ValidationError, |
| 6 | +} from "@chat-adapter/shared"; |
3 | 7 | import type { |
4 | 8 | Adapter, |
5 | 9 | AdapterPostableMessage, |
@@ -978,35 +982,35 @@ export class WhatsAppAdapter |
978 | 982 | } |
979 | 983 |
|
980 | 984 | if (status) { |
981 | | - this.logger.warn( |
982 | | - "WhatsApp typing indicator ignores custom status text", |
983 | | - { status, threadId, messageId } |
984 | | - ); |
| 985 | + this.logger.warn("WhatsApp typing indicator ignores custom status text", { |
| 986 | + status, |
| 987 | + threadId, |
| 988 | + messageId, |
| 989 | + }); |
985 | 990 | } |
986 | 991 |
|
987 | | - try { |
988 | | - const response = await this.graphApiRequest<WhatsAppTypingIndicatorResponse>(`/${this.phoneNumberId}/messages`, { |
989 | | - messaging_product: "whatsapp", |
990 | | - status: "read", |
991 | | - message_id: messageId, |
992 | | - typing_indicator: { |
993 | | - type: "text", |
994 | | - }, |
995 | | - }); |
| 992 | + const response = |
| 993 | + await this.graphApiRequest<WhatsAppTypingIndicatorResponse>( |
| 994 | + `/${this.phoneNumberId}/messages`, |
| 995 | + { |
| 996 | + messaging_product: "whatsapp", |
| 997 | + status: "read", |
| 998 | + message_id: messageId, |
| 999 | + typing_indicator: { |
| 1000 | + type: "text", |
| 1001 | + }, |
| 1002 | + } |
| 1003 | + ); |
996 | 1004 |
|
997 | | - if (!response.success) { |
998 | | - this.logger.error("WhatsApp typing indicator failed", { |
| 1005 | + if (!response.success) { |
| 1006 | + this.logger.error( |
| 1007 | + "WhatsApp typing indicator failed: API returned success=false", |
| 1008 | + { |
999 | 1009 | messageId, |
1000 | 1010 | threadId, |
1001 | | - }); |
1002 | | - throw new Error("WhatsApp typing indicator failed"); |
1003 | | - } |
1004 | | - } catch (error) { |
1005 | | - this.logger.error("WhatsApp typing indicator failed", { |
1006 | | - error, |
1007 | | - messageId, |
1008 | | - threadId, |
1009 | | - }); |
| 1011 | + } |
| 1012 | + ); |
| 1013 | + throw new AdapterError("WhatsApp typing indicator failed", "whatsapp"); |
1010 | 1014 | } |
1011 | 1015 | } |
1012 | 1016 |
|
@@ -1217,7 +1221,10 @@ export class WhatsAppAdapter |
1217 | 1221 | body: errorBody, |
1218 | 1222 | path, |
1219 | 1223 | }); |
1220 | | - throw new Error(`WhatsApp API error: ${response.status} ${errorBody}`); |
| 1224 | + throw new AdapterError( |
| 1225 | + `WhatsApp API error: ${response.status} ${errorBody}`, |
| 1226 | + "whatsapp" |
| 1227 | + ); |
1221 | 1228 | } |
1222 | 1229 |
|
1223 | 1230 | return response.json() as Promise<T>; |
|
0 commit comments