diff --git a/config/language.json b/config/language.json index e09c427..413b6ef 100644 --- a/config/language.json +++ b/config/language.json @@ -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): ", - "Adam: I'm planning a trip to Yellowstone national park on April 12th. Can you find some hotels for me to stay?", - "Alfred(Agent): ", - "Adam: Lets select the first one", - "Alfred(Agent): ", - "Adam: Sure, John A. Smith, john.smith@example.com, (555) 123-4567", - "Alfred(Agent): ", + "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, john.smith@example.com, (555) 123-4567.", "Adam: Sure, lets confirm!", - "Alfred(Agent): ", - - "---on the date of travel---", - "Adam: Can you find the best route from Denver?", - "Alfred(Agent): ", - "Adam: ⁠Lets go with route 1", - "Alfred(Agent): ", - "Adam: Can you find some ev chargin stations along the way?", - "Alfred(Agent): ", + + "---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): ", - "Adam: Sure, lets initate the order", - "Alfred(Agent): ", - "Adam: Sure, lets confirm", - "Alfred(Agent): ", + "---Charging stopped due to an error---", - "Alfred(Agent): ", - "Adam: Yes, please!", - "Alfred(Agent): ", - "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." ] } \ No newline at end of file diff --git a/config/message.json b/config/message.json index 85c1697..ac7cbd6 100644 --- a/config/message.json +++ b/config/message.json @@ -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." } } -} \ No newline at end of file +} diff --git a/controllers/Bot.js b/controllers/Bot.js index a21ceaa..71023ed 100644 --- a/controllers/Bot.js +++ b/controllers/Bot.js @@ -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){ @@ -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}`); @@ -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') { @@ -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]); @@ -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; @@ -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 @@ -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:{ @@ -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')) diff --git a/controllers/ControlCenter.js b/controllers/ControlCenter.js index 5ca19d6..31f1dcd 100644 --- a/controllers/ControlCenter.js +++ b/controllers/ControlCenter.js @@ -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:"", diff --git a/services/AI.js b/services/AI.js index 2d6f50b..d89207f 100644 --- a/services/AI.js +++ b/services/AI.js @@ -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, }) diff --git a/services/Actions.js b/services/Actions.js index 84b7315..e955ff4 100644 --- a/services/Actions.js +++ b/services/Actions.js @@ -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, diff --git a/services/MapService.js b/services/MapService.js index 342d49a..6df0153 100644 --- a/services/MapService.js +++ b/services/MapService.js @@ -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; }