import type { IExecuteFunctions } from 'n8n-workflow'; export type SinchRegion = 'us' | 'eu' | 'br'; export type SinchChannel = 'SMS' | 'WHATSAPP' | 'RCS' | 'MESSENGER' | 'VIBERBM'; export type MessageStatus = 'queued' | 'sent' | 'failed'; export interface SinchCredentials { keyId: string; keySecret: string; region: SinchRegion; projectId: string; appId: string; } export interface OAuth2TokenResponse { access_token: string; token_type: string; expires_in: number; } export interface WhatsAppChannelTemplate { template_id: string; language_code: string; parameters?: Record; } export interface TemplateMessage { channel_template: { WHATSAPP: WhatsAppChannelTemplate; }; } export interface WhatsAppTemplate { name: string; language: string; state?: string; category?: string; details?: { components?: Array<{ type: string; text?: string; examples?: string[]; }>; }; } export interface ListTemplatesResponse { templates: WhatsAppTemplate[]; next_page_token?: string; } export interface SendMessageRequest { app_id: string; recipient: { identified_by?: { channel_identities: Array<{ channel: SinchChannel; identity: string; app_id?: string; }>; }; contact_id?: string; }; message: { text_message?: { text: string; }; template_message?: TemplateMessage; }; channel_priority_order?: SinchChannel[]; channel_properties?: { SMS_SENDER?: string; }; callback_url?: string; message_metadata?: string; } export interface SendMessageResponse { message_id: string; accepted_time: string; } export interface ListMessagesParams { [key: string]: string | number | boolean | undefined; app_id?: string; contact_id?: string; conversation_id?: string; start_time?: string; end_time?: string; page_size?: number; page_token?: string; channel?: SinchChannel; } export interface ListMessagesResponse { messages: ConversationMessage[]; next_page_token?: string; } export interface ConversationMessage { id: string; direction: 'TO_CONTACT' | 'TO_APP' | 'UNDEFINED_DIRECTION'; accept_time: string; channel_identity: { channel: SinchChannel; identity: string; app_id?: string; }; contact_id?: string; conversation_id?: string; app_message?: { text_message?: { text: string; }; }; contact_message?: { text_message?: { text: string; }; }; metadata?: string; } export interface GetMessageResponse { id: string; direction: 'TO_CONTACT' | 'TO_APP' | 'UNDEFINED_DIRECTION'; accept_time: string; channel_identity: { channel: SinchChannel; identity: string; app_id?: string; }; contact_id?: string; conversation_id?: string; metadata?: string; injected?: boolean; sender_id?: string; processing_mode?: 'CONVERSATION' | 'DISPATCH'; app_message?: { text_message?: { text: string; }; }; contact_message?: { text_message?: { text: string; }; }; } export interface ProviderSendParams { to: string; message: string; from?: string; smsSender?: string; callbackUrl?: string; metadata?: string; helpers: IExecuteFunctions['helpers']; credentials: SinchCredentials; } export interface ProviderSendResult { status: MessageStatus; messageId?: string; acceptedTime?: string; raw?: unknown; requestBody?: unknown; error?: string; } export interface IssSubscriptionResponse { subscriptionId: string; } export interface SinchWebhookData { subscriptionId?: string; } export interface MessageDeliveryWebhook { app_id?: string; project_id?: string; event_time?: string; accepted_time?: string; message_delivery_report?: { message_id: string; conversation_id: string; status: string; channel_identity: { channel: SinchChannel; identity: string; app_id?: string; }; contact_id?: string; metadata?: string; }; } export interface MessageDeliveryOutput { messageId: string; conversationId: string; deliveryStatus: string; channel: string; contactIdentity: string; contactId: string; appId: string; projectId: string; eventTime: string; acceptedTime: string; metadata: string; } export interface ProviderSendWhatsAppParams { to: string; templateId: string; languageCode: string; parameters?: Record; helpers: IExecuteFunctions['helpers']; credentials: SinchCredentials; }