Skip to content

iqomp/capacitor-sms-sender

Repository files navigation

capacitor-sms-sender

Send SMS directly from capacitor app

Install

npm install capacitor-sms-sender
npx cap sync

Example

import { SmsSender } from 'capacitor-sms-sender'

let opts = {
    id: 1,
    sim: 0,
    phone: '+123020021',
    text: 'Hi There'
}
SmsSender.send(opts)
    .then(res => {
        console.log(res)
    })

SmsSender.addListener('smsSenderDelivered', res => {
    console.log(res)
})

API

send(...)

send(opts: SmsSenderOptions) => Promise<SmsSenderResult>

Send a text sms to a number from a specified sim index

Param Type
opts SmsSenderOptions

Returns: Promise<SmsSenderResult>

Since: 1.0.0


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check status of permissions

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request the required permissions

Returns: Promise<PermissionStatus>


addListener('smsSenderDelivered', ...)

addListener(eventName: 'smsSenderDelivered', listenerFunc: (result: SmsSenderResult) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for sms status update

Param Type
eventName 'smsSenderDelivered'
listenerFunc (result: SmsSenderResult) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all registered listeners

Since: 1.0.0


Interfaces

SmsSenderResult

Prop Type Description Since
id int Message SMS id 1.0.0
status string Delivery status, possible value are 'FAILED', 'SENT', or 'DELIVERED' 1.0.0

SmsSenderOptions

Prop Type Description Since
id int SMS Message id 1.0.0
sim int Device SIM index 1.0.0
phone string Target phone number 1.0.0
text string SMS Message 1.0.0

PermissionStatus

Prop Type Description Since
send_sms PermissionState SEND_SMS Permission 1.0.0
read_phone_state PermissionState READ_PHONE_STATE Permission 1.0.0

PluginListenerHandle

Prop Type
remove () => Promise<void>

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'