UNPKG

expo-sms-manager

Version:

Complete SMS management module for React Native/Expo - send, receive, and manage SMS messages

203 lines 9.67 kB
import { EventSubscription } from 'expo-modules-core'; import { SmsMessage, SmsError, SmsSendOptions, SmsSendResult, SmsMultipleResult, SimCardInfo, SignalStrengthInfo, SmsProgressEvent, SmsSentEvent, SmsDeliveredEvent, ExpoSmsManagerModuleEvents } from './ExpoSmsManager.types'; export type { SmsMessage, SmsError, SmsSendOptions, SmsSendResult, SmsMultipleResult, SimCardInfo, SignalStrengthInfo, SmsProgressEvent, SmsSentEvent, SmsDeliveredEvent, ExpoSmsManagerModuleEvents }; /** * Checks if the current platform supports SMS operations * @returns true if platform is Android, false otherwise */ export declare function isSupported(): boolean; /** * Checks if the app has all required SMS permissions (READ, RECEIVE, SEND) * @returns true if all SMS permissions are granted */ export declare function hasPermissions(): boolean; /** * Sends an SMS message directly without opening the SMS app * * IMPORTANT: By default, this returns immediately after sending to the network * without waiting for delivery confirmation. Set requestStatusReport: true and * waitForDelivery: true if you need delivery confirmation, but be aware that * delivery reports may not always arrive, especially on physical devices. * * @param phoneNumber The recipient's phone number * @param message The SMS message content * @param options Optional sending configuration * @returns Promise that resolves with send result including messageId and status */ export declare function sendSms(phoneNumber: string, message: string, options?: SmsSendOptions): Promise<SmsSendResult>; /** * Sends an SMS message with delivery tracking * This is a convenience method that enables delivery tracking but doesn't block * * @param phoneNumber The recipient's phone number * @param message The SMS message content * @param options Optional sending configuration * @returns Promise that resolves immediately after sending, with delivery events sent separately */ export declare function sendSmsWithTracking(phoneNumber: string, message: string, options?: Omit<SmsSendOptions, 'requestStatusReport' | 'waitForDelivery'>): Promise<SmsSendResult>; /** * Sends an SMS message and waits for delivery confirmation * WARNING: This may take a long time or timeout on physical devices * * @param phoneNumber The recipient's phone number * @param message The SMS message content * @param options Optional sending configuration * @returns Promise that resolves when delivery is confirmed or times out */ export declare function sendSmsAndWaitForDelivery(phoneNumber: string, message: string, options?: Omit<SmsSendOptions, 'requestStatusReport' | 'waitForDelivery'>): Promise<SmsSendResult>; /** * Sends an SMS message to multiple recipients * @param phoneNumbers Array of recipient phone numbers * @param message The SMS message content * @param options Optional sending configuration * @returns Promise that resolves with array of results for each number */ export declare function sendSmsToMultiple(phoneNumbers: string[], message: string, options?: SmsSendOptions): Promise<SmsMultipleResult[]>; /** * Sends a long SMS message (automatically splits into multiple parts) * @param phoneNumber The recipient's phone number * @param message The long SMS message content * @param options Optional sending configuration * @returns Promise that resolves with send result */ export declare function sendLongSms(phoneNumber: string, message: string, options?: SmsSendOptions): Promise<SmsSendResult>; /** * Gets information about available SIM cards * @returns Array of SIM card information */ export declare function getAvailableSimCards(): SimCardInfo[]; /** * Checks the signal strength of a specific SIM slot * @param simSlot The SIM slot index (0 for first SIM, 1 for second) * @returns Promise that resolves with signal strength information */ export declare function checkSignalStrength(simSlot?: number): Promise<SignalStrengthInfo>; /** * Starts listening for incoming SMS messages * @returns Promise that resolves with success message * @throws Error if permissions are not granted or if starting fails */ export declare function startSmsListener(): Promise<string>; /** * Stops listening for incoming SMS messages * @returns Promise that resolves with success message */ export declare function stopSmsListener(): Promise<string>; /** * Retrieves SMS messages from a specific phone number * @param phoneNumber The phone number to filter messages from * @param limit Maximum number of messages to retrieve (default: 10) * @returns Promise that resolves with array of SMS messages */ export declare function getSmsFromNumber(phoneNumber: string, limit?: number): Promise<SmsMessage[]>; /** * Retrieves the most recent SMS messages * @param limit Maximum number of messages to retrieve (default: 10) * @returns Promise that resolves with array of recent SMS messages */ export declare function getRecentSms(limit?: number): Promise<SmsMessage[]>; /** * Finds SMS messages containing specific text * @param searchText Text to search for in SMS messages * @param limit Maximum number of messages to retrieve (default: 10) * @returns Promise that resolves with array of matching SMS messages */ export declare function findSmsWithText(searchText: string, limit?: number): Promise<SmsMessage[]>; /** * Adds a listener for SMS received events * @param listener Function to call when SMS is received * @returns EventSubscription object for removing the listener */ export declare function addSmsListener(listener: ExpoSmsManagerModuleEvents['onSmsReceived']): EventSubscription; /** * Adds a listener for SMS reader error events * @param listener Function to call when an error occurs * @returns EventSubscription object for removing the listener */ export declare function addErrorListener(listener: ExpoSmsManagerModuleEvents['onError']): EventSubscription; /** * Adds a listener for SMS send progress events * @param listener Function to call when send progress updates * @returns EventSubscription object for removing the listener */ export declare function addSmsProgressListener(listener: ExpoSmsManagerModuleEvents['onSmsProgress']): EventSubscription; /** * Adds a listener for SMS sent confirmation events * @param listener Function to call when SMS is sent * @returns EventSubscription object for removing the listener */ export declare function addSmsSentListener(listener: ExpoSmsManagerModuleEvents['onSmsSent']): EventSubscription; /** * Adds a listener for SMS delivered confirmation events * @param listener Function to call when SMS is delivered * @returns EventSubscription object for removing the listener */ export declare function addSmsDeliveredListener(listener: ExpoSmsManagerModuleEvents['onSmsDelivered']): EventSubscription; /** * Utility function to extract OTP from SMS message * @param message SMS message text * @param length Expected OTP length (default: 4-8 digits) * @returns Extracted OTP string or null if not found */ export declare function extractOtp(message: string, length?: number): string | null; /** * Utility function to check if SMS is from a specific sender pattern * @param sender Sender address/number * @param pattern Pattern to match (can include wildcards with *) * @returns true if sender matches pattern */ export declare function matchesSenderPattern(sender: string, pattern: string): boolean; /** * Utility function to validate phone number format * @param phoneNumber Phone number to validate * @returns true if phone number appears valid */ export declare function isValidPhoneNumber(phoneNumber: string): boolean; /** * Utility function to format phone number for sending * @param phoneNumber Phone number to format * @param countryCode Optional country code to prepend * @returns Formatted phone number */ export declare function formatPhoneNumber(phoneNumber: string, countryCode?: string): string; /** * Utility to check if message will be sent as multipart * @param message The message text * @returns true if message will be split into multiple parts */ export declare function willBeSentAsMultipart(message: string): boolean; /** * Calculate number of SMS parts for a message * @param message The message text * @returns Number of SMS parts the message will be split into */ export declare function calculateSmsParts(message: string): number; declare const _default: { isSupported: typeof isSupported; hasPermissions: typeof hasPermissions; sendSms: typeof sendSms; sendSmsWithTracking: typeof sendSmsWithTracking; sendSmsAndWaitForDelivery: typeof sendSmsAndWaitForDelivery; sendSmsToMultiple: typeof sendSmsToMultiple; sendLongSms: typeof sendLongSms; getAvailableSimCards: typeof getAvailableSimCards; checkSignalStrength: typeof checkSignalStrength; startSmsListener: typeof startSmsListener; stopSmsListener: typeof stopSmsListener; getSmsFromNumber: typeof getSmsFromNumber; getRecentSms: typeof getRecentSms; findSmsWithText: typeof findSmsWithText; addSmsListener: typeof addSmsListener; addErrorListener: typeof addErrorListener; addSmsProgressListener: typeof addSmsProgressListener; addSmsSentListener: typeof addSmsSentListener; addSmsDeliveredListener: typeof addSmsDeliveredListener; extractOtp: typeof extractOtp; matchesSenderPattern: typeof matchesSenderPattern; isValidPhoneNumber: typeof isValidPhoneNumber; formatPhoneNumber: typeof formatPhoneNumber; willBeSentAsMultipart: typeof willBeSentAsMultipart; calculateSmsParts: typeof calculateSmsParts; }; export default _default; //# sourceMappingURL=index.d.ts.map