@@ -12,7 +12,7 @@ export class GupshupWhatsappService {
12
12
) {
13
13
}
14
14
15
- async sendWhatsappOTP ( smsData : SMSData ) : Promise < SMSResponse > {
15
+ async sendWhatsappOTP ( smsData : SMSData , countryCode : string ) : Promise < SMSResponse > {
16
16
const status : SMSResponse = {
17
17
providerResponseCode : null ,
18
18
status : SMSResponseStatus . failure ,
@@ -26,15 +26,14 @@ export class GupshupWhatsappService {
26
26
27
27
// Generate 4 digit OTP
28
28
const otp = Math . floor ( 1000 + Math . random ( ) * 9000 ) ;
29
-
30
29
try {
31
30
// First opt-in the user
32
31
const optInParams = new URLSearchParams ( ) ;
33
32
optInParams . append ( "method" , "OPT_IN" ) ;
34
33
optInParams . append ( "format" , "text" ) ;
35
34
optInParams . append ( "userid" , process . env . GUPSHUP_WHATSAPP_USERID ) ;
36
35
optInParams . append ( "password" , process . env . GUPSHUP_WHATSAPP_PASSWORD ) ;
37
- optInParams . append ( "phone_number" , `91 ${ smsData . phone } ` ) ;
36
+ optInParams . append ( "phone_number" , `${ countryCode } ${ smsData . phone } ` ) ;
38
37
optInParams . append ( "v" , "1.1" ) ;
39
38
optInParams . append ( "auth_scheme" , "plain" ) ;
40
39
optInParams . append ( "channel" , "WHATSAPP" ) ;
@@ -48,19 +47,19 @@ export class GupshupWhatsappService {
48
47
} ) ;
49
48
50
49
// Then send OTP message
51
- const otpMessage = `${ otp } is your verification code. For your security, do not share this code.` ;
50
+ const otpMessage = process . env . GUPSHUP_WHATSAPP_OTP_TEMPLATE . replace ( '%otp%' , `${ otp } ` ) ;
52
51
53
52
const sendOtpParams = new URLSearchParams ( ) ;
54
53
sendOtpParams . append ( "method" , "SENDMESSAGE" ) ;
55
54
sendOtpParams . append ( "userid" , process . env . GUPSHUP_WHATSAPP_USERID ) ;
56
55
sendOtpParams . append ( "password" , process . env . GUPSHUP_WHATSAPP_PASSWORD ) ;
57
- sendOtpParams . append ( "send_to" , smsData . phone ) ;
56
+ sendOtpParams . append ( "send_to" , ` ${ countryCode } ${ smsData . phone } ` ) ;
58
57
sendOtpParams . append ( "v" , "1.1" ) ;
59
58
sendOtpParams . append ( "format" , "json" ) ;
60
59
sendOtpParams . append ( "msg_type" , "TEXT" ) ;
61
60
sendOtpParams . append ( "msg" , otpMessage ) ;
62
61
sendOtpParams . append ( "isTemplate" , "true" ) ;
63
- sendOtpParams . append ( "footer" , "This code expires in 30 minute." ) ;
62
+ sendOtpParams . append ( "footer" , process . env . GUPSHUP_WHATSAPP_OTP_TEMPLATE_FOOTER ) ;
64
63
65
64
let sendOtpURL = process . env . GUPSHUP_WHATSAPP_BASEURL + '?' + sendOtpParams . toString ( ) ;
66
65
@@ -76,7 +75,6 @@ export class GupshupWhatsappService {
76
75
77
76
status . providerSuccessResponse = JSON . stringify ( response . data ) ;
78
77
status . status = SMSResponseStatus . success ;
79
- status . messageID = otp . toString ( ) ;
80
78
}
81
79
82
80
return status ;
0 commit comments