Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added:Control Certer Backend APIs #45

Merged
merged 15 commits into from
Apr 3, 2024
Merged

Conversation

shreyvishal
Copy link
Collaborator

@shreyvishal shreyvishal commented Mar 29, 2024

Description

Added:Control Certer Backend APIs

Features covered

Create a control center

Changes made

Added APIs for Control Center UI

Screenshots/recordings

NA

Testing

NA

Self checks

  • Code follows coding style guidelines.
  • All tests pass successfully.
  • No new linting errors or warnings.
  • Documentation is updated, if necessary.
  • Dependencies are updated, if required.
  • There are no merge conflicts.

Reviewer Suggestions

NA

@shreyvishal shreyvishal requested a review from mayurvir March 29, 2024 14:31
@shreyvishal shreyvishal mentioned this pull request Mar 29, 2024
10 tasks
Copy link
Contributor

@mayurvir mayurvir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of things not right with this PR.

Also, the code never worked, it failed existing test cases and are missing environment variables. Please fix and add additional test cases for the changes.

try {
const { orderId } = req.body
const messageBody = CANCEL_BOOKING_MESSAGE;
const getOrderFulfillmentDetails = await axios.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could re-use the call_api function instead of all axios calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done

} from '../utils/constants.js'

const action = new Actions()
const TOURISM_STRAPI_URL = process.env.TOURISM_STRAPI_URL || ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New environment variables need to be added to the .env.sample file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

server.js Outdated
dotenv.config()
import express from 'express'
import bodyParser from 'body-parser'
import logger from './utils/logger.js'
import messageController from './controllers/Bot.js'
import DBService from './services/DBService.js'

import { notificationController } from './controllers/Notification.js'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find this controller.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
)

await action.send_message(TWILIO_RECEPIENT_NUMBER, messageBody)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using twilio recipient number, shouldn't this be the user's number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From where should the user's number be provided, from the payload sent by the FE?? @mayurvir

}


export const notificationController = async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we we can put one controller inside another. Why can't we use a function for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need Clarity for this @mayurvir


const client = Twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)

export const sendWhatsappNotification = async (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the send_message() from Actions.js service here?

@@ -0,0 +1,11 @@
export const STRAPI_TOURISM_TOKEN =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets keep this under the config folder. Its not a utility. As a practise, things that are not keys etc. should be kept here so Token should be an environment variable whereas TOURISM_STRAPI_URL should be under config .

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@shreyvishal shreyvishal force-pushed the feat/create_control_center branch from a9090a2 to 93ea8ac Compare April 1, 2024 14:00
@shreyvishal shreyvishal requested a review from mayurvir April 1, 2024 14:00
@shreyvishal shreyvishal force-pushed the feat/create_control_center branch from 93ea8ac to f25fdaa Compare April 1, 2024 14:06
@@ -11,6 +11,14 @@
{ "role": "system", "content": "A typical order flow should be search > select > init > confirm."},
{ "role": "system", "content": "Use the response of search from assistant to select items from the list of items provided by the assistant."},
{ "role": "system", "content": "Use the response of search request from assistant for filling transaction_id, bpp_id, bpp_uri in the context of all calls except `search`."},
{ "role": "system", "content": "For `select`, `init`, `confirm`, you must use the item `id` as part of the payload for selected item instead of name or any other key."}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the prompt changed for line #14?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed.

],
"PRESETS" : {
"bap_id": "mit-ps-bap.becknprotocol.io",
"bap_uri": "https://mit-ps-bap.becknprotocol.io",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here under openai.json.

One that things like bap_id, bap_uri etc are now part of registry.json
Strapi url is not openai related config, it should be under a different file like config.json or constants.js file that you have created.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done.

const config = JSON.parse(readFileSync('./config/openai.json'))

const action = new Actions()
const STRAPI_TOURISM_TOKEN = process.env.STRAPI_TOURISM_TOKEN || ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to re-decalre STRAPI_TOURISM_TOKEN or STRAPI_TOURISM_TOKEN as they can be used directly from the environment variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

try {
const { orderId } = req.body
if(!orderId){
return res.status(500).json({message:"Order Id is Required", status:false})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500 is for internal server error, you should use 400 for a bad request , typically used for missing data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
const validOrderId = await action.call_api(`${config.PRESETS.TOURISM_STRAPI_URL}/orders/${orderId}`,'GET',{},{ Authorization: `Bearer ${STRAPI_TOURISM_TOKEN}`})
if(!validOrderId.status){
return res.send({ message: `Invalid Order Id`, status:false })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status should be 400, its sending 200 when the order id is invalid. Isn't it a bad request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

describe('API tests for /notify endpoint for an end to end Notify Request', () => {
it('Should test unsuccess response for invalid whatsapp number.', async () => {
const response = await request(app).post('/notify').send({
"userNo":"+919123456789"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a valid number, it should be something like "INVALID_NUMBER", a string is invalid number and it will defiitely faill. Test cases should be written in such a way that they always do what they are supposed to do. They should not be flaky (which works sometimes and dont work sometimes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const response = await request(app).post('/notify').send({

})
expect(response._body.status.status).to.not.equal('failed')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its succes case, why are we testing for failure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const response = await request(app).post('/notify').send({
"userNo":process.env.TEST_RECEPIENT_NUMBER
})
expect(response._body.status.status).to.not.equal('failed')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its a sucess, response, why is the status being test against failed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const response = await request(app).post('/cancel-booking').send({
"orderId":"1"
})
expect(response._body.message).equal('Notification delivered')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check for status also.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tests/unit/controllers/controlCenter.test.js Show resolved Hide resolved
@shreyvishal shreyvishal requested a review from mayurvir April 3, 2024 04:34
Copy link
Contributor

@mayurvir mayurvir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIggest problem is with unit tests not running fully.

],
"PRESETS" : {
"bap_id": "mit-ps-bap.becknprotocol.io",
"bap_uri": "https://mit-ps-bap.becknprotocol.io",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done.

@@ -11,6 +11,14 @@
{ "role": "system", "content": "A typical order flow should be search > select > init > confirm."},
{ "role": "system", "content": "Use the response of search from assistant to select items from the list of items provided by the assistant."},
{ "role": "system", "content": "Use the response of search request from assistant for filling transaction_id, bpp_id, bpp_uri in the context of all calls except `search`."},
{ "role": "system", "content": "For `select`, `init`, `confirm`, you must use the item `id` as part of the payload for selected item instead of name or any other key."}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed.

@@ -46,21 +46,22 @@ describe.skip('Test cases for process_instruction function', ()=> {
})
})

describe('should test send_message()', () => {
describe.only('should test send_message()', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tests/unit/services/actions.test.js Show resolved Hide resolved
@mayurvir mayurvir merged commit 6481168 into main Apr 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants