From e3af183e0c3d51292e14f4285dd8c71e4c564b39 Mon Sep 17 00:00:00 2001 From: MaximBelov Date: Tue, 11 Jul 2023 20:25:02 +0300 Subject: [PATCH] feat(sms-retriever-api): add plugin (#4528) --- .../plugins/sms-retriever-api/index.ts | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/@awesome-cordova-plugins/plugins/sms-retriever-api/index.ts diff --git a/src/@awesome-cordova-plugins/plugins/sms-retriever-api/index.ts b/src/@awesome-cordova-plugins/plugins/sms-retriever-api/index.ts new file mode 100644 index 000000000..ac754b75e --- /dev/null +++ b/src/@awesome-cordova-plugins/plugins/sms-retriever-api/index.ts @@ -0,0 +1,105 @@ +import { Injectable } from '@angular/core'; +import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core'; +import { Observable, fromEvent } from 'rxjs'; + +export interface IncomingSMS { + message: string; + [key: string]: any; +} + +export enum SmsRetrieverStatus { + AlreadyStarted = 'SMS_RETRIEVER_ALREADY_STARTED', + Started = 'SMS_RETRIEVER_STARTED', + Done = 'SMS_RETRIEVER_DONE', + Timeout = 'TIMEOUT', +} + +/** + * @name SmsRetrieverApi + * @description + * This plugin retries the SMS which arrive without requiring READ permissions. + * @usage + * ```typescript + * import { SmsRetrieverApi } from '@awesome-cordova-plugins/sms-retriever-api/ngx'; + * + * + * constructor(private SmsRetrieverApi: SmsRetrieverApi) { } + * + * ... + * + * + * this.SmsRetrieverApi.getHashString() + * .then((res: any) => console.log(res)) + * .catch((error: any) => console.error(error)); + * this.SmsRetrieverApi.startWatch() + * .subscribe( + * (res: any) => console.log(res), + * (error: any) => console.error(error), + * ) + * .catch((error: any) => console.error(error)); + * this.onSMSArrive.onSMSArrive() + * .subscribe(() => { console.log(); }); + * ``` + */ +@Plugin({ + pluginName: 'SmsRetriever', + plugin: 'cordova-plugin-sms-retriever', + pluginRef: 'cordova.plugins.SMSRetriever', + repo: 'https://github.com/andreszs/cordova-plugin-sms-retriever', + install: 'ionic cordova plugin add cordova-plugin-sms-retriever --variable PLAY_SERVICES_VERSION="18.0.1"', + installVariables: ['PLAY_SERVICES_VERSION'], + platforms: ['Android'], +}) +@Injectable() +export class SmsRetrieverApi extends AwesomeCordovaNativePlugin { + /** + * This function start watching message arrive event and retrieve message text. + * + * @returns {Observable} Returns an observable that resolves when retries SMS text or TIMEOUT after 5 min. + */ + @Cordova({ + observable: true, + }) + startWatch(): Observable { + return; + } + + /** + * This function stop watching message. + * + * @returns {Promise} Returns a promise that resolves when successfully remove sms listener. + */ + @Cordova() + stopWatch(): Promise { + return; + } + + /** + * This function is to get hash string of APP. + * + * @returns {Promise} Returns a promise that resolves when successfully generate hash of APP. + */ + @Cordova() + getHashString(): Promise { + return; + } + + /** + * Opens a dialog to select your mobile numbers saved in phone and returns selected phone number. + * + * @returns {Promise} Returns a promise that resolves when successfully get phone number + */ + @Cordova() + getPhoneNumber(): Promise { + return; + } + + /** + * Watch incoming SMS event listener + * + * @returns {Observable} + */ + onSMSArrive(): Observable { + return fromEvent(document, 'onSMSArrive'); + } +}