Skip to content

Commit

Permalink
fix: scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
techsavvyash committed Jun 13, 2024
1 parent bebca87 commit c70c1d8
Show file tree
Hide file tree
Showing 8 changed files with 2,769 additions and 2,308 deletions.
865 changes: 483 additions & 382 deletions src/app.controller.ts

Large diffs are not rendered by default.

348 changes: 190 additions & 158 deletions src/common/utils.ts

Large diffs are not rendered by default.

507 changes: 273 additions & 234 deletions src/modules/aiTools/ai-tools.service.ts

Large diffs are not rendered by default.

203 changes: 113 additions & 90 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { decryptRequest, encryptRequest } from "../../common/utils";
import { Message } from "@prisma/client";
import { MonitoringService } from "../monitoring/monitoring.service";


@Injectable()
export class UserService {
private logger: CustomLogger;
Expand All @@ -19,173 +18,197 @@ export class UserService {
this.logger = new CustomLogger("UserService");
}

async sendOTP(
mobileNumber: string,
type: string = 'Mobile'
): Promise<any> {
async sendOTP(mobileNumber: string, type: string = "Mobile"): Promise<any> {
try {
let encryptedData = await encryptRequest(`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"Token\":\"${this.configService.get("PM_KISSAN_TOKEN")}\"}`)
let encryptedData = await encryptRequest(
`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"Token\":\"${this.configService.get(
"PM_KISSAN_TOKEN"
)}\"}`
);
console.log("encrypted data: ", encryptedData);
let data = JSON.stringify({
"EncryptedRequest": `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`
EncryptedRequest: `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`,
});

let config = {
method: 'post',
method: "post",
maxBodyLength: Infinity,
url: `${this.configService.get("PM_KISAN_BASE_URL")}/chatbototp`,
headers: {
'Content-Type': 'application/json'
headers: {
"Content-Type": "application/json",
},
data : data
data: data,
};

let response: any = await axios.request(config)
console.log("sendOTP",response.status)
let response: any = await axios.request(config);
console.log("sendOTP", response.status);
if (response.status >= 200 && response.status < 300) {
response = await response.data
let decryptedData: any = await decryptRequest(response.d.output,encryptedData.d.token)
response.d.output = JSON.parse(decryptedData.d.decryptedvalue)
response["status"] = response.d.output.Rsponce != "False" ? "OK" : "NOT_OK"
return response
response = await response.data;
let decryptedData: any = await decryptRequest(
response.d.output,
encryptedData.d.token
);
response.d.output = JSON.parse(decryptedData.d.decryptedvalue);
response["status"] =
response.d.output.Rsponce != "False" ? "OK" : "NOT_OK";
return response;
} else {
return {
d: {
output: {
status: 'False',
Message: 'Try again'
}
}
}
status: "False",
Message: "Try again",
},
},
};
}
} catch (error) {
console.log(error)
console.log(error);
return {
d: {
output: {
status: 'False',
Message: 'Try again'
}
}
}
status: "False",
Message: "Try again",
},
},
};
}
}

async verifyOTP(
mobileNumber: string,
otp: string,
type: string = 'Mobile'
type: string = "Mobile"
): Promise<any> {

try {
let encryptedData = await encryptRequest(`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"OTP\":\"${otp}\",\"Token\":\"${this.configService.get("PM_KISSAN_TOKEN")}\"}`)
let encryptedData = await encryptRequest(
`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"OTP\":\"${otp}\",\"Token\":\"${this.configService.get(
"PM_KISSAN_TOKEN"
)}\"}`
);
let data = JSON.stringify({
"EncryptedRequest": `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`
EncryptedRequest: `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`,
});

let config = {
method: 'post',
method: "post",
maxBodyLength: Infinity,
url: `${this.configService.get("PM_KISAN_BASE_URL")}/ChatbotOTPVerified`,
headers: {
'Content-Type': 'application/json'
url: `${this.configService.get(
"PM_KISAN_BASE_URL"
)}/ChatbotOTPVerified`,
headers: {
"Content-Type": "application/json",
},
data : data
data: data,
};

let response: any = await axios.request(config)
console.log("verifyOTP",response.status)
let response: any = await axios.request(config);
console.log("verifyOTP", response.status);
if (response.status >= 200 && response.status < 300) {
response = await response.data
let decryptedData: any = await decryptRequest(response.d.output,encryptedData.d.token)
console.log(decryptedData)
response.d.output = JSON.parse(decryptedData.d.decryptedvalue)
response["status"] = response.d.output.Rsponce != "False" ? "OK" : "NOT_OK"
return response
response = await response.data;
let decryptedData: any = await decryptRequest(
response.d.output,
encryptedData.d.token
);
console.log(decryptedData);
response.d.output = JSON.parse(decryptedData.d.decryptedvalue);
response["status"] =
response.d.output.Rsponce != "False" ? "OK" : "NOT_OK";
return response;
} else {
return {
d: {
output: {
status: 'False',
Message: 'Try again'
}
}
}
status: "False",
Message: "Try again",
},
},
};
}
} catch (error) {
console.log(error)
console.log(error);
return {
d: {
output: {
status: 'False',
Message: 'Try again'
}
}
}
status: "False",
Message: "Try again",
},
},
};
}
}

async getUserData(
mobileNumber: string,
type: string = 'Mobile'
type: string = "Mobile"
): Promise<any> {
let res: any;
try {
let encryptedData = await encryptRequest(`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"Token\":\"${this.configService.get("PM_KISSAN_TOKEN")}\"}`)
let encryptedData = await encryptRequest(
`{\"Types\":\"${type}\",\"Values\":\"${mobileNumber}\",\"Token\":\"${this.configService.get(
"PM_KISSAN_TOKEN"
)}\"}`
);
let data = JSON.stringify({
"EncryptedRequest": `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`
EncryptedRequest: `${encryptedData.d.encryptedvalu}@${encryptedData.d.token}`,
});

let config = {
method: 'post',
method: "post",
maxBodyLength: Infinity,
url: `${this.configService.get("PM_KISAN_BASE_URL")}/ChatbotUserDetails`,
headers: {
'Content-Type': 'application/json'
url: `${this.configService.get(
"PM_KISAN_BASE_URL"
)}/ChatbotUserDetails`,
headers: {
"Content-Type": "application/json",
},
data : data
data: data,
};
res = await axios.request(config)
console.log("getUserData",res.status)
res = await axios.request(config);
console.log("getUserData", res.status);
if (res.status >= 200 && res.status < 300) {
res = await res.data
let decryptedData: any = await decryptRequest(res.d.output,encryptedData.d.token)
res.d.output = JSON.parse(decryptedData.d.decryptedvalue)
res["status"] = res.d.output.Rsponce != "False" ? "OK" : "NOT_OK"
res = await res.data;
let decryptedData: any = await decryptRequest(
res.d.output,
encryptedData.d.token
);
res.d.output = JSON.parse(decryptedData.d.decryptedvalue);
res["status"] = res.d.output.Rsponce != "False" ? "OK" : "NOT_OK";
} else {
this.monitoringService.incrementUnableToGetUserDetailsCount()
this.monitoringService.incrementUnableToGetUserDetailsCount();
res = {
d: {
output: {
status: 'False',
Message: 'Unable to get user details'
}
}
}
status: "False",
Message: "Unable to get user details",
},
},
};
}
} catch (error) {
this.monitoringService.incrementUnableToGetUserDetailsCount()
this.monitoringService.incrementUnableToGetUserDetailsCount();
return {
d: {
output: {
status: 'False',
Message: 'Unable to get user details'
}
}
}
status: "False",
Message: "Unable to get user details",
},
},
};
}
return res
return res;
}

async likeQuery(id): Promise<Message> {
// try {
await this.prisma.$queryRawUnsafe(`
await this.prisma.$queryRawUnsafe(`
UPDATE "Message" SET
"reaction" = 1
WHERE "id" = '${id}'`);
// } catch {
// return null;
// }
this.monitoringService.incrementPositveFeedbackCount()
this.monitoringService.incrementPositveFeedbackCount();
return this.prisma.$queryRawUnsafe(`
SELECT * from "Message" where id = '${id}'
`);
Expand All @@ -197,7 +220,7 @@ export class UserService {
UPDATE "Message" SET
"reaction" = -1
WHERE "id" = '${id}'`);
this.monitoringService.incrementNegativeFeedbackCount()
this.monitoringService.incrementNegativeFeedbackCount();
} catch {
return null;
}
Expand Down
34 changes: 20 additions & 14 deletions src/xstate/prompt/prompt.gaurds.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
export const promptGuards = {
ifText: (_, event) => event.data.prompt.input.type == "Text",

ifText: (_,event) => event.data.prompt.input.type == "Text",
ifAudio: (_, event) => event.data.inputType == "Audio",

ifAudio: (_,event) => event.data.inputType == "Audio",
ifMultipleAadhaar: (_, event) =>
event.data == "This mobile number taged with multiple records.",

ifMultipleAadhaar: (_,event) => event.data == "This mobile number taged with multiple records.",
ifInValidScheme: (_, event) =>
!VALID_SCHEMES.includes(event.data.prompt.input.schemeName),

ifNoRecordsFound: (context,event)=> event.data == `No Record Found for this (${context.userAadhaarNumber}) Aadhar/Ben_id/Mobile.`,
ifNoRecordsFound: (context, event) =>
event.data ==
`No Record Found for this (${context.userAadhaarNumber}) Aadhar/Ben_id/Mobile.`,

ifOTPSend: (_,event)=> event.data == 'OTP send successfully!',
ifOTPSend: (_, event) => event.data == "OTP send successfully!",

ifTryAgain: (_,event)=> event.data == 'Try again',
ifTryAgain: (_, event) => event.data == "Try again",

ifNotValidAadhaar: (_,event) => event.data == "Please enter a valid Beneficiary ID/Aadhaar Number/Phone number",
ifNotValidAadhaar: (_, event) =>
event.data ==
"Please enter a valid Beneficiary ID/Aadhaar Number/Phone number",

ifInvalidOTP: (_,event) => event.data == "OTP not verified",

resendOTP: (_,event) => event.data.query == "resend OTP",
ifInvalidOTP: (_, event) => event.data == "OTP not verified",

ifOTPHasBeenVerified: (context,_) => context.isOTPVerified,
resendOTP: (_, event) => event.data.query == "resend OTP",

ifInvalidClassifier: (_,event) => event.data.class == "invalid",
ifOTPHasBeenVerified: (context, _) => context.isOTPVerified,

ifConvoStarterOrEnder: (_,event) => event.data.class == "convo"
ifInvalidClassifier: (_, event) => event.data.class == "invalid",

}
ifConvoStarterOrEnder: (_, event) => event.data.class == "convo",
};
Loading

0 comments on commit c70c1d8

Please sign in to comment.