import { Injectable } from '@nestjs/common'; import axios from 'axios'; import { IntegrationStrategy, IntegrationResult, } from '../integration.strategy'; @Injectable() export class WhatsAppStrategy implements IntegrationStrategy { async sendMessage( to: string, message: string, config: any, ): Promise { try { const { accessToken, phoneNumberId, apiVersion = 'v17.0' } = config; const url = `https://graph.facebook.com/${apiVersion}/${phoneNumberId}/messages`; const payload = { messaging_product: 'whatsapp', to: to, type: 'text', text: { body: message, }, }; const response = await axios.post(url, payload, { headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, }); return { success: true, provider: 'whatsapp', service: 'API', messageId: response.data.messages[0].id, timestamp: new Date(), }; } catch (error) { return { success: false, provider: 'whatsapp', service: 'API', error: error.message, timestamp: new Date(), }; } } validateConfig(config: any): boolean { return !!(config.accessToken && config.phoneNumberId); } }