import { AbstractNotificationService, CartService, ClaimService, EventBusService, Fulfillment, FulfillmentProviderService, FulfillmentService, GiftCardService, LineItem, LineItemService, Order, OrderService, ProductVariantService, ReturnService, ShippingMethod, StoreService, SwapService, TotalsService } from "@medusajs/medusa"; import { Logger, MedusaContainer } from "@medusajs/medusa/dist/types/global"; import twilio from "twilio"; import { EntityManager } from "typeorm"; import MessagingResponse from "twilio/lib/twiml/MessagingResponse"; import { MessageInstance, MessageListInstanceCreateOptions } from "twilio/lib/rest/api/v2010/account/message"; import { WhatsappSession } from "../types"; import { ConversationInstance } from "twilio/lib/rest/conversations/v1/conversation"; import { ParticipantInstance } from "twilio/lib/rest/conversations/v1/conversation/participant"; import { MessageInstance as ConversationMessageInstance } from "twilio/lib/rest/conversations/v1/conversation/message"; import { ContentInstance } from "twilio/lib/rest/content/v1/content"; export interface WhatsappInterfaceServiceParams { manager: EntityManager; eventBusService: EventBusService; logger: Logger; storeService: StoreService; orderService: OrderService; returnService: ReturnService; swapService: SwapService; cartService: CartService; lineItemService: LineItemService; claimService: ClaimService; fulfillmentService: FulfillmentService; fulfillmentProviderService: FulfillmentProviderService; totalsService: TotalsService; productVariantService: ProductVariantService; giftCardService: GiftCardService; [key: string]: unknown; } export interface WhatsappInterfaceOptions { account_sid: string; auth_token: string; whatsappHandlerInterface: string; medusaServerHost: string; medusaServerPort: string; medusaServerProtocol: string; } export type ErrorCallBack = (error: Error | null, item: MessageInstance) => any; export declare class WhatsappService extends AbstractNotificationService { logger_: Logger; protected manager_: EntityManager; protected transactionManager_: EntityManager; eventBusService: EventBusService; twilioClient: twilio.Twilio; options: WhatsappInterfaceOptions; static identifier: string; fulfillmentProviderService_: FulfillmentProviderService; storeService_: StoreService; lineItemService_: LineItemService; orderService_: OrderService; cartService_: CartService; claimService_: ClaimService; returnService_: ReturnService; swapService_: SwapService; fulfillmentService_: FulfillmentService; totalsService_: TotalsService; productVariantService_: ProductVariantService; giftCardService_: GiftCardService; constructor(container: WhatsappInterfaceServiceParams, options: WhatsappInterfaceOptions); id: string; is_installed: boolean; withTransaction(transactionManager?: EntityManager): this; processReceivedMessage(container: MedusaContainer, body: T, activeSession: WhatsappSession): Promise; processReceivedConversationPrehook(container: MedusaContainer, body: T): Promise<{ body?: string; author?: string; attributes?: Record; } | { friendly_name?: string; }>; processReceivedConversationPosthook(container: MedusaContainer, body: T): Promise<{ body?: string; author?: string; attributes?: Record; } | { friendly_name?: string; }>; /** * * @param sender - senders phone number in iso format "eg: +1xxxxxxxx" * @param receiver - receiver phone number in iso format "eg: +1xxxxxxxx" * @param message - the text message * @param otherOptions - other twilio params * @param error an error call back * @returns */ sendTextMessage({ message, receiver, sender, otherOptions, error, }: { sender: string; receiver: string; message?: string; otherOptions?: Partial; error?: ErrorCallBack; }): Promise; sendNotification(event: string, data: { sender: string; receiver: string; message?: string; } & Record, attachmentGenerator: any): Promise<{ to: string; status: string; data: Record; }>; resendNotification(notification: any, config: any, attachmentGenerator: any): Promise<{ to: string; status: string; data: Record; }>; fetchAttachments(event: any, data: { return_request: { items?: LineItem[]; shipping_method?: ShippingMethod; shipping_data?: any; }; order: Order; }, attachmentGenerator: { createReturnInvoice: (arg0: any, arg1: any) => any; }): Promise; fetchData(event: any, eventData: any, attachmentGenerator: any): Promise; orderShipmentCreatedData({ id, fulfillment_id }: { id: any; fulfillment_id: any; }, attachmentGenerator: any): Promise<{ locale: unknown; order: Order; date: string; email: string; fulfillment: Fulfillment; tracking_links: import("@medusajs/medusa").TrackingLink[]; tracking_number: string; }>; orderCanceledData({ id }: { id: any; }): Promise<{ locale: unknown; has_discounts: number; has_gift_cards: number; date: string; items: any; discounts: any[]; subtotal: string; gift_card_total: string; tax_total: string; discount_total: string; shipping_total: string; total: string; object: "order"; status: import("@medusajs/medusa").OrderStatus; fulfillment_status: import("@medusajs/medusa").FulfillmentStatus; payment_status: import("@medusajs/medusa").PaymentStatus; display_id: number; cart_id: string; cart: import("@medusajs/medusa").Cart; customer_id: string; customer: import("@medusajs/medusa").Customer; email: string; billing_address_id: string; billing_address: import("@medusajs/medusa").Address; shipping_address_id: string; shipping_address: import("@medusajs/medusa").Address; region_id: string; region: import("@medusajs/medusa").Region; currency_code: string; currency: import("@medusajs/medusa").Currency; tax_rate: number; gift_cards: import("@medusajs/medusa").GiftCard[]; shipping_methods: ShippingMethod[]; payments: import("@medusajs/medusa").Payment[]; fulfillments: Fulfillment[]; returns: import("@medusajs/medusa").Return[]; claims: import("@medusajs/medusa").ClaimOrder[]; refunds: import("@medusajs/medusa").Refund[]; swaps: import("@medusajs/medusa").Swap[]; draft_order_id: string; draft_order: import("@medusajs/medusa").DraftOrder; edits: import("@medusajs/medusa").OrderEdit[]; gift_card_transactions: import("@medusajs/medusa").GiftCardTransaction[]; canceled_at: Date; metadata: Record; no_notification: boolean; idempotency_key: string; external_id: string; sales_channel_id: string; sales_channel: import("@medusajs/medusa").SalesChannel; sales_channels?: import("@medusajs/medusa").SalesChannel[]; shipping_tax_total: number; raw_discount_total: number; item_tax_total: number; refunded_total: number; paid_total: number; refundable_amount: number; gift_card_tax_total: number; returnable_items?: LineItem[]; id: string; created_at: Date; updated_at: Date; }>; orderPlacedData({ id }: { id: any; }): Promise<{ locale: unknown; has_discounts: number; has_gift_cards: number; date: string; items: (LineItem & { totals: { original_total: number; total: number; subtotal: any; }; discounted_price: string; price: string; })[]; discounts: any[]; subtotal_ex_tax: string; subtotal: string; gift_card_total: string; tax_total: string; discount_total: string; shipping_total: string; total: string; object: "order"; status: import("@medusajs/medusa").OrderStatus; fulfillment_status: import("@medusajs/medusa").FulfillmentStatus; payment_status: import("@medusajs/medusa").PaymentStatus; display_id: number; cart_id: string; cart: import("@medusajs/medusa").Cart; customer_id: string; customer: import("@medusajs/medusa").Customer; email: string; billing_address_id: string; billing_address: import("@medusajs/medusa").Address; shipping_address_id: string; shipping_address: import("@medusajs/medusa").Address; region_id: string; region: import("@medusajs/medusa").Region; currency_code: string; currency: import("@medusajs/medusa").Currency; tax_rate: number; gift_cards: import("@medusajs/medusa").GiftCard[]; shipping_methods: ShippingMethod[]; payments: import("@medusajs/medusa").Payment[]; fulfillments: Fulfillment[]; returns: import("@medusajs/medusa").Return[]; claims: import("@medusajs/medusa").ClaimOrder[]; refunds: import("@medusajs/medusa").Refund[]; swaps: import("@medusajs/medusa").Swap[]; draft_order_id: string; draft_order: import("@medusajs/medusa").DraftOrder; edits: import("@medusajs/medusa").OrderEdit[]; gift_card_transactions: import("@medusajs/medusa").GiftCardTransaction[]; canceled_at: Date; metadata: Record; no_notification: boolean; idempotency_key: string; external_id: string; sales_channel_id: string; sales_channel: import("@medusajs/medusa").SalesChannel; sales_channels?: import("@medusajs/medusa").SalesChannel[]; shipping_tax_total: number; raw_discount_total: number; item_tax_total: number; refunded_total: number; paid_total: number; refundable_amount: number; gift_card_tax_total: number; returnable_items?: LineItem[]; id: string; created_at: Date; updated_at: Date; }>; gcCreatedData({ id }: { id: any; }): Promise<{ locale: unknown; email: unknown; display_value: string; message: unknown; code: string; value: number; balance: number; region_id: string; region: import("@medusajs/medusa").Region; order_id: string; order: Order; is_disabled: boolean; ends_at: Date; tax_rate: number; metadata: Record; deleted_at: Date; id: string; created_at: Date; updated_at: Date; }>; returnRequestedData({ id, return_id }: { id: any; return_id: any; }): Promise<{ locale: unknown; has_shipping: boolean; email: string; items: LineItem[]; subtotal: string; shipping_total: string; refund_amount: string; return_request: { refund_amount: string; status: import("@medusajs/medusa").ReturnStatus; items: import("@medusajs/medusa").ReturnItem[]; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; order_id: string; order: Order; shipping_method: ShippingMethod; location_id: string; shipping_data: Record; received_at: Date; no_notification: boolean; metadata: Record; idempotency_key: string; id: string; created_at: Date; updated_at: Date; }; order: Order; date: string; }>; swapReceivedData({ id }: { id: any; }): Promise<{ locale: unknown; swap: import("@medusajs/medusa").Swap; order: Order; return_request: import("@medusajs/medusa").Return; date: string; swap_link: string; email: string; items: { totals: { unit_price: number; quantity: number; subtotal: number; tax_total: number; total: number; original_total: number; original_tax_total: number; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; discount_total: number; raw_discount_total: number; }; price: string; cart_id: string; cart: import("@medusajs/medusa").Cart; order_id: string; order: Order; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; adjustments: import("@medusajs/medusa").LineItemAdjustment[]; original_item_id?: string; order_edit_id?: string; order_edit?: import("@medusajs/medusa").OrderEdit; title: string; description: string; thumbnail: string; is_return: boolean; is_giftcard: boolean; should_merge: boolean; allow_discounts: boolean; has_shipping: boolean; unit_price: number; variant_id: string; variant: import("@medusajs/medusa").ProductVariant; product_id: string; quantity: number; fulfilled_quantity: number; returned_quantity: number; shipped_quantity: number; metadata: Record; includes_tax: boolean; refundable?: number; subtotal?: number; tax_total?: number; total?: number; original_total?: number; original_tax_total?: number; discount_total?: number; raw_discount_total?: number; gift_card_total?: number; id: string; created_at: Date; updated_at: Date; }[]; return_items: { totals: { unit_price: number; quantity: number; subtotal: number; tax_total: number; total: number; original_total: number; original_tax_total: number; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; discount_total: number; raw_discount_total: number; }; price: string; cart_id: string; cart: import("@medusajs/medusa").Cart; order_id: string; order: Order; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; adjustments: import("@medusajs/medusa").LineItemAdjustment[]; original_item_id?: string; order_edit_id?: string; order_edit?: import("@medusajs/medusa").OrderEdit; title: string; description: string; thumbnail: string; is_return: boolean; is_giftcard: boolean; should_merge: boolean; allow_discounts: boolean; has_shipping: boolean; unit_price: number; variant_id: string; variant: import("@medusajs/medusa").ProductVariant; product_id: string; quantity: number; fulfilled_quantity: number; returned_quantity: number; shipped_quantity: number; metadata: Record; includes_tax: boolean; refundable?: number; subtotal?: number; tax_total?: number; total?: number; original_total?: number; original_tax_total?: number; discount_total?: number; raw_discount_total?: number; gift_card_total?: number; id: string; created_at: Date; updated_at: Date; }[]; return_total: string; tax_total: string; refund_amount: string; additional_total: string; }>; swapCreatedData({ id }: { id: any; }): Promise<{ locale: unknown; swap: import("@medusajs/medusa").Swap; order: Order; return_request: import("@medusajs/medusa").Return; date: string; swap_link: string; email: string; items: { totals: { unit_price: number; quantity: number; subtotal: number; tax_total: number; total: number; original_total: number; original_tax_total: number; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; discount_total: number; raw_discount_total: number; }; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; price: string; discounted_price: string; cart_id: string; cart: import("@medusajs/medusa").Cart; order_id: string; order: Order; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; adjustments: import("@medusajs/medusa").LineItemAdjustment[]; original_item_id?: string; order_edit_id?: string; order_edit?: import("@medusajs/medusa").OrderEdit; title: string; description: string; thumbnail: string; is_return: boolean; is_giftcard: boolean; should_merge: boolean; allow_discounts: boolean; has_shipping: boolean; unit_price: number; variant_id: string; variant: import("@medusajs/medusa").ProductVariant; product_id: string; quantity: number; fulfilled_quantity: number; returned_quantity: number; shipped_quantity: number; metadata: Record; includes_tax: boolean; refundable?: number; subtotal?: number; tax_total?: number; total?: number; original_total?: number; original_tax_total?: number; discount_total?: number; raw_discount_total?: number; gift_card_total?: number; id: string; created_at: Date; updated_at: Date; }[]; return_items: { totals: { unit_price: number; quantity: number; subtotal: number; tax_total: number; total: number; original_total: number; original_tax_total: number; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; discount_total: number; raw_discount_total: number; }; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; price: string; discounted_price: string; cart_id: string; cart: import("@medusajs/medusa").Cart; order_id: string; order: Order; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; adjustments: import("@medusajs/medusa").LineItemAdjustment[]; original_item_id?: string; order_edit_id?: string; order_edit?: import("@medusajs/medusa").OrderEdit; title: string; description: string; thumbnail: string; is_return: boolean; is_giftcard: boolean; should_merge: boolean; allow_discounts: boolean; has_shipping: boolean; unit_price: number; variant_id: string; variant: import("@medusajs/medusa").ProductVariant; product_id: string; quantity: number; fulfilled_quantity: number; returned_quantity: number; shipped_quantity: number; metadata: Record; includes_tax: boolean; refundable?: number; subtotal?: number; tax_total?: number; total?: number; original_total?: number; original_tax_total?: number; discount_total?: number; raw_discount_total?: number; gift_card_total?: number; id: string; created_at: Date; updated_at: Date; }[]; return_total: string; refund_amount: string; additional_total: string; }>; itemsReturnedData(data: any): Promise<{ locale: unknown; has_shipping: boolean; email: string; items: LineItem[]; subtotal: string; shipping_total: string; refund_amount: string; return_request: { refund_amount: string; status: import("@medusajs/medusa").ReturnStatus; items: import("@medusajs/medusa").ReturnItem[]; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; order_id: string; order: Order; shipping_method: ShippingMethod; location_id: string; shipping_data: Record; received_at: Date; no_notification: boolean; metadata: Record; idempotency_key: string; id: string; created_at: Date; updated_at: Date; }; order: Order; date: string; }>; swapShipmentCreatedData({ id, fulfillment_id }: { id: any; fulfillment_id: any; }): Promise<{ locale: unknown; swap: import("@medusajs/medusa").Swap; order: Order; items: { thumbnail: any; price: string; discounted_price: string; quantity: number; cart_id: string; cart: import("@medusajs/medusa").Cart; order_id: string; order: Order; swap_id: string; swap: import("@medusajs/medusa").Swap; claim_order_id: string; claim_order: import("@medusajs/medusa").ClaimOrder; tax_lines: import("@medusajs/medusa").LineItemTaxLine[]; adjustments: import("@medusajs/medusa").LineItemAdjustment[]; original_item_id?: string; order_edit_id?: string; order_edit?: import("@medusajs/medusa").OrderEdit; title: string; description: string; is_return: boolean; is_giftcard: boolean; should_merge: boolean; allow_discounts: boolean; has_shipping: boolean; unit_price: number; variant_id: string; variant: import("@medusajs/medusa").ProductVariant; product_id: string; fulfilled_quantity: number; returned_quantity: number; shipped_quantity: number; metadata: Record; includes_tax: boolean; refundable?: number; subtotal?: number; tax_total?: number; total?: number; original_total?: number; original_tax_total?: number; discount_total?: number; raw_discount_total?: number; gift_card_total?: number; id: string; created_at: Date; updated_at: Date; }[]; date: string; email: string; tax_amount: string; paid_total: string; return_total: string; refund_amount: string; additional_total: string; fulfillment: Fulfillment; tracking_links: import("@medusajs/medusa").TrackingLink[]; tracking_number: string; }>; claimShipmentCreatedData({ id, fulfillment_id }: { id: any; fulfillment_id: any; }): Promise<{ locale: unknown; email: string; claim: import("@medusajs/medusa").ClaimOrder; order: Order; fulfillment: Fulfillment; tracking_links: import("@medusajs/medusa").TrackingLink[]; tracking_number: string; }>; restockNotificationData({ variant_id, emails }: { variant_id: any; emails: any; }): Promise<{ product: { thumbnail: any; title: string; subtitle: string; description: string; handle: string; is_giftcard: boolean; status: import("@medusajs/medusa").ProductStatus; images: import("@medusajs/medusa").Image[]; options: import("@medusajs/medusa").ProductOption[]; variants: import("@medusajs/medusa").ProductVariant[]; categories: import("@medusajs/medusa").ProductCategory[]; profile_id: string; profile: import("@medusajs/medusa").ShippingProfile; profiles: import("@medusajs/medusa").ShippingProfile[]; weight: number; length: number; height: number; width: number; hs_code: string; origin_country: string; mid_code: string; material: string; collection_id: string; collection: import("@medusajs/medusa").ProductCollection; type_id: string; type: import("@medusajs/medusa").ProductType; tags: import("@medusajs/medusa").ProductTag[]; discountable: boolean; external_id: string; metadata: Record; sales_channels: import("@medusajs/medusa").SalesChannel[]; deleted_at: Date; id: string; created_at: Date; updated_at: Date; }; variant: import("@medusajs/medusa").ProductVariant; variant_id: any; emails: any; }>; userPasswordResetData(data: any): any; customerPasswordResetData(data: any): any; orderRefundCreatedData({ id, refund_id }: { id: any; refund_id: any; }): Promise<{ order: Order; refund: import("@medusajs/medusa").Refund; refund_amount: string; email: string; }>; processItems_(items: any, taxRate: any, currencyCode: any): any; humanPrice_(amount: any, currency: any): string; normalizeThumbUrl_(url: any): any; extractLocale(fromOrder: any): Promise; createTemplateParameters(...args: string[]): Record; createTemplatedMessage({ messageId, to: phone, parameters, contentSid, }: { messageId: string; to: string; parameters: Record; contentSid: string; }): { id: string; sender: string; receiver: string; contentSid: string; contentVariables: string; }; sendContentTemplate({ messageId, to, parameters, contentSid, }: { messageId: string; to: string; parameters: Record; contentSid: string; }): Promise; stopConversation({ conversationId }: { conversationId: string; }): Promise; isInConversation(phoneNumber: string, proxyPhoneNumber?: string): Promise; isParticipantInConversation(participant: ParticipantInstance): Promise; startConversation({ sender, receiver, }: { sender: string; receiver: string; }): Promise; getExistingConversation(conversationId: string): Promise; joinAgent(conversationId: string, agentRealNumber: string): Promise; findOldConversations(phone: string, messageBinding: { address: string; proxyAddress: string; }): Promise; releaseAgent({ conversationId, agentPhoneNumber, }: { conversationId: string; agentPhoneNumber: string; }): Promise; releaseUser({ conversationId, phone, }: { conversationId: string; phone: string; }): Promise; joinUser({ conversationId, phone, }: { conversationId: string; phone: string; }): Promise; sendConversationMessageFromAgent(conversationId: string, message: string, agentNumber: string): Promise; sendConversationContentTemplateFromAgent({ conversationId, contentSid, contentVariables, agentNumber, }: { conversationId: string; contentSid: string; contentVariables: Record; agentNumber: string; }): Promise; startWhatsappAgentConversation(sender: string, receiver: string, agentRealNumber?: string, otherPartyRealNumber?: string): Promise; getContentTemplate(contentId: string): Promise; findActiveConversationBetween2parties({ agentRealNumber, otherParty, }: { agentRealNumber: string; otherParty: string; }): Promise; } export default WhatsappService;