Skip to content

Commit

Permalink
whatapi auth and whatapi new api intergration done
Browse files Browse the repository at this point in the history
  • Loading branch information
Sm1pleScr1pt committed Sep 18, 2024
1 parent 66de584 commit b9eea41
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
3 changes: 2 additions & 1 deletion blocks/applyloanform/loanformapiurls.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 56 additions & 26 deletions blocks/whatsappservice/otppopup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchAPI } from "../../scripts/scripts.js";
import { generateOTPAPI, getAccessToken, resendOtpAPI, showNetworkFailedScreen, verfyOtpAPI } from "../applyloanform/loanformapi.js";
import { getWhatAPIAuthURL } from "../applyloanform/loanformapiurls.js";
import { getWhatAPIAuthURL, getWhatAPIURL } from "../applyloanform/loanformapiurls.js";

let time_limit = 30;
let time_out;
Expand Down Expand Up @@ -287,27 +287,51 @@ function getWhatsappServicesApi(mobileNumber) {
}


function getWhatAPIAuth(){
export function getWhatAPIAuth() {
let requestObj = {
requestJson: {
"username": "test.kumar@getcogno.ai",
"password": "Success@123$",
"bot_id": "1"
}
}
username: "test.kumar@getcogno.ai",
password: "Success@123$",
bot_id: "1",
},
};

return new Promise(function (resolve, reject) {
fetchAPI("POST",
getWhatAPIAuthURL, requestObj)
.then(function (response) {
resolve(response.responseJson);
}).catch(function (err) {
showNetworkFailedScreen(err);
})
});
fetchAPI("POST", getWhatAPIAuthURL, requestObj)
.then(function (response) {
resolve(response.responseJson);
})
.catch(function (err) {
showNetworkFailedScreen(err);
});
});
}
debugger
getWhatAPIAuth();

export function getWhatAPI(authToken, mobileNumber) {
let requestObj = {
requestJson: {
authorization: authToken,
campaign_id: "87",
whatsapp_bsp: "6",
client_data: {
phone_number: "+91" + mobileNumber,
name: "Name",
},
},
};

return new Promise(function (resolve, reject) {
fetchAPI("POST", getWhatAPIURL, requestObj)
.then(function (response) {
resolve(response.responseJson);
})
.catch(function (err) {
showNetworkFailedScreen(err);
});
});
}



export function sucessPopupCloe() {
document.querySelector(".successContainer").style.display = "none";
Expand All @@ -321,15 +345,21 @@ function verfiyOtp(otpValue) {
if (response.returnResponse.statusCode == 100) {
document.querySelector(".wrongotpmessage").style.display = "none";
document.querySelector(".wrongotpmessage").textContent = "";
getWhatsappServicesApi(mobileNumber).then(function (res) {
document.querySelector(".successContainer").style.display = "block";
document.querySelector(".loan-form-heading-parent").style.display = "none";
document.querySelector(".loan-form-otp").style.display = "none";
document.querySelector(".loan-form-button-container").style.display = "none";
document.querySelector(".mobileNumber").innerText = mobileNumber;

removeLoader();
});
getWhatAPIAuth().then(function ({status, auth_token}){
if(status == 200){
getWhatAPI(auth_token, mobileNumber).then(function (res) {
document.querySelector(".successContainer").style.display = "block";
document.querySelector(".loan-form-heading-parent").style.display = "none";
document.querySelector(".loan-form-otp").style.display = "none";
document.querySelector(".loan-form-button-container").style.display = "none";
document.querySelector(".mobileNumber").innerText = mobileNumber;
removeLoader();
});
}
}).catch((error)=> {
console.log(error);
})
// getWhatsappServicesApi(mobileNumber);
} else {
document.querySelector(".wrongotpmessage").textContent = response.returnResponse.message;
document.querySelector(".wrongotpmessage").style.display = "block";
Expand Down

0 comments on commit b9eea41

Please sign in to comment.