11import axios , { AxiosInstance } from "axios" ;
22import { Base64 } from "js-base64" ;
33import { CustomAxiosError } from "./error" ;
4- import { initSMSToken , sendLMS , sendShortSMS } from "./modules/gabia-service" ;
4+ import { initSMSToken , sendLMS , sendShortSMS , sendMMS } from "./modules/gabia-service" ;
55import { IGabiaAPIConfiguration } from "./types/IGabiaAPIConfiguration" ;
66import { IDefaultRes , IDefaultResData , IGetAccessToken } from "./types/IGabiaResponse" ;
77
@@ -52,7 +52,7 @@ class GabiaSMS {
5252 ) ;
5353
5454 try {
55- const data : any = await this . call < IGetAccessToken > ( initSMSToken ( ) ) ;
55+ const data : IGetAccessToken = await this . call < IGetAccessToken > ( initSMSToken ( ) ) ;
5656
5757 if ( data === undefined ) {
5858
@@ -92,10 +92,8 @@ class GabiaSMS {
9292 throw new Error ( 'Please check the message.' ) ;
9393 }
9494
95+ await this . getAccesstoken ( ) ;
9596 try {
96-
97- await this . getAccesstoken ( ) ;
98-
9997 return ( await this . call < IDefaultRes > ( sendShortSMS ( {
10098 phone,
10199 callback,
@@ -126,7 +124,6 @@ class GabiaSMS {
126124 }
127125
128126 await this . getAccesstoken ( ) ;
129-
130127 try {
131128 return ( await this . call < IDefaultRes > ( sendLMS ( {
132129 phone,
@@ -140,6 +137,37 @@ class GabiaSMS {
140137 }
141138 }
142139
140+ async sendMMS (
141+ phone : string ,
142+ callback : string ,
143+ message : string ,
144+ subject : string ,
145+ images : File [ ] ,
146+ ) : Promise < IDefaultResData > {
147+ if ( message === '' ) {
148+ throw new Error ( 'Please check the message.' ) ;
149+ }
150+
151+ await this . getAccesstoken ( ) ;
152+
153+ const formData = new FormData ( ) ;
154+ formData . append ( 'phone' , phone ) ;
155+ formData . append ( 'callback' , callback ) ;
156+ formData . append ( 'message' , message ) ;
157+ formData . append ( 'subject' , subject ) ;
158+ formData . append ( 'refkey' , this . refKEY ) ;
159+ formData . append ( 'img_cnt' , String ( images . length ) ) ;
160+ for ( const [ index , value ] of images . entries ( ) ) {
161+ formData . append ( `images${ index } ` , value ) ;
162+ }
163+
164+ try {
165+ return ( await this . call < IDefaultRes > ( sendMMS ( formData ) ) ) . data ;
166+ } catch ( err ) {
167+ throw new CustomAxiosError ( err ) ;
168+ }
169+ }
170+
143171 private _base64KeyEncode ( key : string ) : string {
144172
145173 return 'Basic ' + Base64 . encode ( `${ this . gabiaId } :${ key } ` ) ;
0 commit comments