Skip to content

Commit

Permalink
Added code that is deployed on server
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurvir committed Apr 9, 2024
1 parent 8009c7d commit 6b18803
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 102 deletions.
106 changes: 46 additions & 60 deletions config/language.json
Original file line number Diff line number Diff line change
@@ -1,88 +1,74 @@
{
"FULFILLMENT_STATUS_CODES":{
"order-picked-up":{
"message": "Your order has been picked up"
"FULFILLMENT_STATUS_CODES": {
"order-picked-up": {
"message": "Your order's on its way!"
},
"order-on-the-way": {
"message": "Your order is on the way"
"message": "Hang tight! Your order's cruising over to you."
},
"order-delivered":{
"message": "Your order has been delivered"
"order-delivered": {
"message": "Package alert! Your order's been delivered."
},
"ticket-issued":{
"message": "Your ticket has been issued"
},
"ticket-validated":{
"message": "Your ticket has been validated"
"ticket-issued": {
"message": "All set! Your ticket's ready to go."
},
"ticket-validated": {
"message": "You're all good! Your ticket's been validated."
},
"charging-started": {
"message": "Your charging has started"
},
"charging-stopped":{
"message": "Your charging has stopped"
},
"charger-not-working":{
"message": "Hi, it looks likes your charger is not working. DO you want to find other chargin stations?"
},
"charging-completed":{
"message": "Hi, your chargin is complete!"
"message": "Juice up! Your charging session's begun."
},
"charging-stopped": {
"message": "Heads up! Your charging session's been paused."
},
"charger-not-working": {
"message": "Uh-oh, looks like there's a glitch with your charger ⚡😓. Need help finding another spot? 📍🔍"
},
"charging-completed": {
"message": "Charged and ready! Your battery's full."
},
"checked-in": {
"message": "You have succesfully checked-in to your stay!"
},
"checked-out":{
"message": "You have succesfully checked-out from your stay!"
"message": "Welcome! You've successfully checked in."
},
"checked-out": {
"message": "Safe travels! You've checked out."
}
},
"ALL_MESSAGES": {
"session_cleared": "Your session has been cleared! You're all set to start a new one.",
"session_and_profile_cleared": "Both your session and profile have been cleared! You're ready to start fresh.",
"route_selected": "Your route is all set! Here's your navigation link: ${url}. What's next on your agenda?",
"request_in_progress": "Hang tight! We're currently processing your request...",
"request_processed": "All done! Your request has been processed and we're getting your response ready...",
"request_failed": "Oops, we hit a snag processing your request. Want to give it another shot?",
"request_to_beckn_failed": "Looks like we couldn't get that request through. How about we try something different?",
"request_in_progress": "Hang tight! I'm currently processing your request...",
"request_processed": "All done! Your request has been processed and I'm getting your response ready...",
"request_failed": "Oops, hit a snag processing your request. Want to give it another shot?",
"request_to_beckn_failed": "Looks like I couldn't get that request through. How about we try something different?",
"incident_on_road": "Heads up: ${message}. Could you share your current location so I can find some alternative routes for you?",
"formatting_failed": "We had trouble understanding that instruction.",
"api_call_failed": "Oops, we ran into an issue calling the API.",
"failed_to_process_instruction": "We had trouble processing that instruction.",
"formatting_failed": "I had trouble understanding that instruction.",
"api_call_failed": "Oops, I ran into an issue calling the API.",
"failed_to_process_instruction": "I had trouble processing that instruction.",
"missing_source": "Mind sharing the starting point for your journey?",
"missing_destination": "Could you let us know your destination?",
"route_list_description": "Here are some route options for you. Which one do you prefer?"
},
"TEST_MESSAGES_USER": [
"---Days before the travel---",
"Adam: Hi Alfred",
"Alfred(Agent): <Responds back>",
"Adam: I'm planning a trip to Yellowstone national park on April 12th. Can you find some hotels for me to stay?",
"Alfred(Agent): <Responds back with the list of hotels>",
"Adam: Lets select the first one",
"Alfred(Agent): <Responds back asking for billing details to initate the order>",
"Adam: Sure, John A. Smith, [email protected], (555) 123-4567",
"Alfred(Agent): <Responds back asking for confirmation>",
"Adam: Hey Alfred, you around?",
"Adam: I’m hitting Yellowstone National Park on April 12th for 2 days. Got any places to stay?",
"Adam: First one sounds awesome. Lets go with that",
"Adam: You got it - John A. Smith, [email protected], (555) 123-4567.",
"Adam: Sure, lets confirm!",
"Alfred(Agent): <Confirms the order and shares the order id>",

"---on the date of travel---",
"Adam: Can you find the best route from Denver?",
"Alfred(Agent): <Responds back with a list of route options. Asks which one to select>",
"Adam: ⁠Lets go with route 1",
"Alfred(Agent): <Shows the selected route on map and shares a navigation link>",
"Adam: Can you find some ev chargin stations along the way?",
"Alfred(Agent): <Shares a list of EV chargins stations and asks to select one>",

"---On the date of travel---",
"Adam: Alfred, can you find the best route to Yellowstone national park from Denver?",
"Adam: lets go with Route 1",
"Adam: Can you find ev chargers on the route?",
"Adam: Lets go with Tesla Supercharger",
"Alfred(Agent): <resonds backn asking to initate the order>",
"Adam: Sure, lets initate the order",
"Alfred(Agent): <responds backn asking for confirmation>",
"Adam: Sure, lets confirm",
"Alfred(Agent): <Confirms the order and shares the order id>",


"---Charging stopped due to an error---",
"Alfred(Agent): <Sends message stating that the charger has some issue, asks to find another one?>",
"Adam: Yes, please!",
"Alfred(Agent): <Shares a list of EV chargins stations and asks to select one>",
"Adam: Lets go with ChargePoint"


"Adam: Yeah, let’s find another charger",
"Adam: Let’s go with the second one.",
"Adam: Sure thing, lets book it",
"Adam: Yeah, let’s do it."
]
}
52 changes: 26 additions & 26 deletions config/message.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"FULFILLMENT_STATUS_CODES":{
"order-picked-up":{
"message": "Your order has been picked up"
"FULFILLMENT_STATUS_CODES": {
"order-picked-up": {
"message": "Your order's on its way!"
},
"order-on-the-way": {
"message": "Your order is on the way"
"message": "Hang tight! Your order's cruising over to you."
},
"order-delivered":{
"message": "Your order has been delivered"
"order-delivered": {
"message": "Package alert! Your order's been delivered."
},
"ticket-issued":{
"message": "Your ticket has been issued"
},
"ticket-validated":{
"message": "Your ticket has been validated"
"ticket-issued": {
"message": "All set! Your ticket's ready to go."
},
"ticket-validated": {
"message": "You're all good! Your ticket's been validated."
},
"charging-started": {
"message": "Your charging has started"
},
"charging-stopped":{
"message": "Your charging has stopped"
},
"charger-not-working":{
"message": "Hi, it looks likes your charger is not working. DO you want to find other chargin stations?"
},
"charging-completed":{
"message": "Hi, your chargin is complete!"
"message": "Juice up! Your charging session's begun."
},
"charging-stopped": {
"message": "Heads up! Your charging session's been paused."
},
"charger-not-working": {
"message": "Uh-oh, looks like there's a glitch with your charger. Need help finding another spot?"
},
"charging-completed": {
"message": "Charged and ready! Your battery's full."
},
"checked-in": {
"message": "You have succesfully checked-in to your stay!"
},
"checked-out":{
"message": "You have succesfully checked-out from your stay!"
"message": "Welcome! You've successfully checked in."
},
"checked-out": {
"message": "Safe travels! You've checked out."
}
}
}
}
29 changes: 18 additions & 11 deletions controllers/Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function process_text(req, res) {
}

try{

// Get profile
const profileResponse = await ai.get_profile_from_text(message, session.profile);
if(profileResponse.status){
Expand All @@ -139,7 +139,11 @@ async function process_text(req, res) {
// check for booking collection

let booking_collection = false; // await ai.check_if_booking_collection(message, [...session.text.slice(-1)]);
if(booking_collection){
if(message === 'clearall'){
session = EMPTY_SESSION;
response.formatted = get_text_by_key('session_and_profile_cleared');
}
else if(booking_collection){
logger.info(`Booking collection found!`);
response.formatted = await ai.get_ai_response_to_query('Share the list of bookings to be made? Please include only hotels and tickets to be booked. It should be a short list with just names of bookings to be made. For e.g. Here is a list of bookings you need to make: \n1. hotel at xyz \n2. Tickets for abc \nWhich one do you want to search first?', session.text);
logger.info(`AI response: ${response.formatted}`);
Expand All @@ -156,7 +160,7 @@ async function process_text(req, res) {
else{

// get action
ai.action = await ai.get_beckn_action_from_text(message, session.text, session.bookings);
ai.action = await ai.get_beckn_action_from_text(message, session.text.slice(-3), session.bookings);

// Reset actions context if action is search
if(ai.action?.action === 'search') {
Expand All @@ -172,10 +176,6 @@ async function process_text(req, res) {
};
response.formatted = get_text_by_key('session_cleared');
}
else if(ai.action?.action === 'clear_all'){
session = EMPTY_SESSION;
response.formatted = get_text_by_key('session_and_profile_cleared');
}
else if(ai.action?.action === 'get_routes'){
const routes = await mapService.generate_routes(message, session.text, session.avoid_point|| []);
const formatting_response = await ai.format_response(routes.data?.routes_formatted || routes.errors, [{ role: 'user', content: message },...session.text]);
Expand All @@ -202,6 +202,7 @@ async function process_text(req, res) {
logger.info(`Image url : ${map_image_url_server}`)
if(map_image_url_server) response.media=[map_image_url_server]
}
session.routes=[]; // reset routes
}
const formatting_response = await ai.format_response(route_response, [{ role: 'user', content: message },...session.text]);
response.formatted = formatting_response.message;
Expand Down Expand Up @@ -248,10 +249,10 @@ async function process_text(req, res) {
}

// if(session.bookings && session.bookings.length>0) session.bookings = await ai.get_bookings_status(session.bookings, session.text);
logger.info(`\u001b[1;34m Bookings status : ${JSON.stringify(ai.bookings)}\u001b[0m`)
// logger.info(`\u001b[1;34m Bookings status : ${JSON.stringify(ai.bookings)}\u001b[0m`)

// update session
session.bookings = ai.bookings;
// session.bookings = ai.bookings;
await db.update_session(sender, session);

// Send response
Expand Down Expand Up @@ -327,7 +328,13 @@ async function process_action(action, text, session, sender=null, format='applic

}

const message = await ai.get_beckn_message_from_text(text, search_context, beckn_context.domain, session.selected_route?.overview_polyline?.points);
let message = null;
message = await ai.get_beckn_message_from_text(text, search_context, beckn_context.domain, session.selected_route?.overview_polyline?.points);
if(!message){
logger.error(`Failed to get message from text: ${text}. Retrying...`)
message = await ai.get_beckn_message_from_text(text, search_context, beckn_context.domain, session.selected_route?.overview_polyline?.points);
}

request = {
status: true,
data:{
Expand All @@ -344,7 +351,7 @@ async function process_action(action, text, session, sender=null, format='applic
request = await ai.get_beckn_request_from_text(text, session.actions.raw, beckn_context, schema, session.profile);
}

if(request.status){
if(request.status && request?.data?.body?.message){
// call api
const api_response = await actionsService.call_api(request.data.url, request.data.method, request.data.body, request.data.headers)
format!='application/json' && await actionsService.send_message(sender, get_text_by_key('request_processed'))
Expand Down
3 changes: 2 additions & 1 deletion controllers/ControlCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ export const notify = async (req, res) => {

export const updateStatus = async (req, res) => {
try {
const { orderId, domain="", status=null } = req.body
let { orderId, domain="", status=null } = req.body
if(!orderId){
return res.status(400).json({message:"Order Id is Required", status:false})
}
orderId = parseInt(orderId);
let DOMAIN_DETAILS = {
url:"",
token:"",
Expand Down
2 changes: 1 addition & 1 deletion services/AI.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class AI {
try{
const completion = await openai.chat.completions.create({
messages: openai_messages,
model: process.env.OPENAI_MODEL_ID,
model: 'gpt-4-0125-preview',
response_format: { type: 'json_object' },
temperature: 0,
})
Expand Down
9 changes: 7 additions & 2 deletions services/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ class Actions {
// This should be imlemented by different baps based on their requirements.
if(request.data.context && request.data.context.action==='search'){
response.data.responses = response.data.responses.filter(res => res.message && res.message.catalog && res.message.catalog.providers && res.message.catalog.providers.length > 0)
if(response.data.responses.length > 0)
response.data.responses = response.data.responses.slice(0, 1);
if(response.data.responses.length > 0) {
response.data.responses = response.data.responses.slice(0, 1);
if(response?.data?.responses[0].message?.catalog?.providers){
response.data.responses[0].message.catalog.providers = response.data.responses[0].message.catalog.providers.slice(0, 3);
}
}

}
responseObject = {
status: true,
Expand Down
2 changes: 1 addition & 1 deletion services/MapService.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MapsService {

response.data.routes_formatted = {
"description": get_text_by_key('route_list_description'),
"routes": response.data.routes.map((route, index) => `Route ${index+1}: ${route.summary}`)
"routes": response.data.routes.map((route, index) => `Route ${index+1}: ${route.summary}\n`)
}
response.status = true;
}
Expand Down

0 comments on commit 6b18803

Please sign in to comment.