Skip to content

Commit 60c952c

Browse files
committed
updated gupshup API for international numbers
1 parent b774f60 commit 60c952c

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/api/api.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class ApiController {
120120
template: null,
121121
type: null,
122122
params: null
123-
});
123+
},countryCode);
124124
} else {
125125
status = await this.otpService.sendOTP(params.phone);
126126
}

src/api/sms/gupshupWhatsapp/gupshupWhatsapp.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class GupshupWhatsappService {
1212
) {
1313
}
1414

15-
async sendWhatsappOTP(smsData: SMSData): Promise<SMSResponse> {
15+
async sendWhatsappOTP(smsData: SMSData, countryCode: string): Promise<SMSResponse> {
1616
const status: SMSResponse = {
1717
providerResponseCode: null,
1818
status: SMSResponseStatus.failure,
@@ -26,15 +26,14 @@ export class GupshupWhatsappService {
2626

2727
// Generate 4 digit OTP
2828
const otp = Math.floor(1000 + Math.random() * 9000);
29-
3029
try {
3130
// First opt-in the user
3231
const optInParams = new URLSearchParams();
3332
optInParams.append("method", "OPT_IN");
3433
optInParams.append("format", "text");
3534
optInParams.append("userid", process.env.GUPSHUP_WHATSAPP_USERID);
3635
optInParams.append("password", process.env.GUPSHUP_WHATSAPP_PASSWORD);
37-
optInParams.append("phone_number", `91${smsData.phone}`);
36+
optInParams.append("phone_number", `${countryCode}${smsData.phone}`);
3837
optInParams.append("v", "1.1");
3938
optInParams.append("auth_scheme", "plain");
4039
optInParams.append("channel", "WHATSAPP");
@@ -48,19 +47,19 @@ export class GupshupWhatsappService {
4847
});
4948

5049
// 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}`);
5251

5352
const sendOtpParams = new URLSearchParams();
5453
sendOtpParams.append("method", "SENDMESSAGE");
5554
sendOtpParams.append("userid", process.env.GUPSHUP_WHATSAPP_USERID);
5655
sendOtpParams.append("password", process.env.GUPSHUP_WHATSAPP_PASSWORD);
57-
sendOtpParams.append("send_to", smsData.phone);
56+
sendOtpParams.append("send_to", `${countryCode}${smsData.phone}`);
5857
sendOtpParams.append("v", "1.1");
5958
sendOtpParams.append("format", "json");
6059
sendOtpParams.append("msg_type", "TEXT");
6160
sendOtpParams.append("msg", otpMessage);
6261
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);
6463

6564
let sendOtpURL = process.env.GUPSHUP_WHATSAPP_BASEURL + '?' + sendOtpParams.toString();
6665

@@ -76,7 +75,6 @@ export class GupshupWhatsappService {
7675

7776
status.providerSuccessResponse = JSON.stringify(response.data);
7877
status.status = SMSResponseStatus.success;
79-
status.messageID = otp.toString();
8078
}
8179

8280
return status;

0 commit comments

Comments
 (0)