Skip to content

Commit

Permalink
Correctsions made for eth workflow to worl
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurvir committed Mar 29, 2024
1 parent 514368c commit 21b9424
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion controllers/Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ async function process_wa_webhook(req, res) {

twiml.message(process_response.formatted)
if(format!='application/json'){
res.type('text/xml').send(twiml.toString())
// res.type('text/xml').send(twiml.toString())
actionsService.send_message(sender, process_response.formatted)
res.send("Done!")
}
else{
raw_yn ? res.send(process_response.raw) : res.send(process_response.formatted)
Expand Down
2 changes: 1 addition & 1 deletion services/AI.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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',
temperature: 0,
response_format: { type: 'json_object' },
})
Expand Down
11 changes: 7 additions & 4 deletions services/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ class Actions {

async send_message(recipient, message) {
try {
await client.messages.create({

const response = await client.messages.create({
body: message,
from: `whatsapp:${twilioNumber}`,
to: `whatsapp:${recipient}`,
to: recipient.includes('whatsapp:') ? recipient : `whatsapp:${recipient}`,
})
logger.info(`Message sent: ${JSON.stringify(response)}`)
return true;
} catch (error) {
logger.error(`Error sending message: ${error.message}`)
throw new Error(`Failed to send message: ${error.message}`)
logger.error(`Error sending message: ${error.message}`)
return false;
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions tests/unit/services/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ describe('should test send_message()', () => {
const recipient = process.env.TEST_RECEPIENT_NUMBER;
const message = "hi, this is a test message";

try {
await actionsService.send_message(recipient, message);

} catch (error) {
throw new Error('Message sending failed');
}
let status = await actionsService.send_message(recipient, message);
expect(status).to.be.true;
});

it('should test send a message via Twilio with a whatsapp prefix', async () => {
const recipient = `whatsapp:${process.env.TEST_RECEPIENT_NUMBER}`;
const message = "hi, this is a test message";

let status = await actionsService.send_message(recipient, message);
expect(status).to.be.true;

});

it('should throw an error for invalid recipient', async () => {
Expand Down

0 comments on commit 21b9424

Please sign in to comment.