@veelit/capacitor-ussd-manager
v0.0.4
Published
The plugin allows the use of the `Android TelephonyManager UssdResponseCallBack` method to dial ussd short codes programmatically and get the response text asynchronously
Downloads
3
Readme
capacitor-ussd-manager
The plugin allows the use of the Android TelephonyManager UssdResponseCallBack
method to dial ussd short codes programmatically and get the response text asynchronously.
Note: This only supports USSD codes that are not session based (i.e where user input is not required after dialling the code).
Install
npm install @veelit/capacitor-ussd-manager
npx cap sync
Permissions
Add the following permission to your AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
API
echo(...)
echo(options: { value: string; }) => Promise<{ value: string; }>
| Param | Type |
| ------------- | ----------------------------------- |
| options
| <code>
{ value: string; }</code>
|
Returns: <code>
Promise<{ value: string; }></code>
requestUssdPermission()
requestUssdPermission() => Promise<void>
callUssd(...)
callUssd(options: { value: string; }) => Promise<{ result: string; code: string; }>
| Param | Type |
| ------------- | ----------------------------------- |
| options
| <code>
{ value: string; }</code>
|
Returns: <code>
Promise<{ result: string; code: string; }></code>
Example Usage
import { UssdManager } from '@veelit/capacitor-ussd-manager';
const callUssdCode = async (shortCode: string) => {
try {
await UssdManager.requestUssdPermission();
const res = await UssdManager.callUssd({ value: shortCode });
setUssdResponse(res);
} catch (error: any) {
setUssdResponse(JSON.parse(error?.message));
}
};