Skip to content

Commit

Permalink
added check gated the plugin-twilio in agent runtime only add it when…
Browse files Browse the repository at this point in the history
… required env vars are found
  • Loading branch information
juanc07 committed Jan 5, 2025
1 parent e34e5ae commit 026c821
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
7 changes: 6 additions & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,12 @@ export async function createAgent(
// character.plugins are handled when clients are added
plugins: [
bootstrapPlugin,
twilioPlugin,
getSecret(character, "TWILIO_ACCOUNT_SID") &&
getSecret(character, "TWILIO_AUTH_TOKEN") &&
getSecret(character, "TWILIO_PHONE_NUMBER") &&
getSecret(character, "TWILIO_WHATSAPP_PHONE_NUMBER")
? twilioPlugin
: null,
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
? confluxPlugin
: null,
Expand Down
9 changes: 2 additions & 7 deletions packages/plugin-twilio/src/actions/sendSms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export const sendSmsAction: Action = {
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;

console.log("CHECK _message: ",_message.content.text);

if (!accountSid || !authToken) {
console.error('TWILIO_ACCOUNT_SID or TWILIO_AUTH_TOKEN is not set');
return false;
Expand Down Expand Up @@ -67,10 +65,6 @@ export const sendSmsAction: Action = {

const twilioNumber = process.env.TWILIO_PHONE_NUMBER; // Your Twilio phone number

console.log('check target mobile number: ', mobileNumberProvidedByUser);
console.log('check messageToSendFromUser: ', messageToSendFromUser);
console.log('check twilioNumber: ', twilioNumber);

if (!twilioNumber) {
console.error('Twilio phone number is missing');

Expand Down Expand Up @@ -140,7 +134,8 @@ export const sendSmsAction: Action = {
from: twilioNumber, // Your Twilio phone number
});

console.log("message body: ", message);
// for debug purposes uncomment this
console.log("check twilio message body: ", message);

const messageFromAgent = `SMS sent successfully to ${mobileNumberProvidedByUser}`;

Expand Down
14 changes: 8 additions & 6 deletions packages/plugin-twilio/src/actions/sendWhatsAppMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ export const sendWhatsAppMessageAction: Action = {
}
}

const twilioNumber = process.env.TWILIO_WHATSAPP_PHONE_NUMBER; // Your Twilio WhatsApp number

console.log('check target mobile number: ', mobileNumberProvidedByUser);
console.log('check messageToSendFromUser: ', messageToSendFromUser);
console.log('check twilioNumber: ', twilioNumber);
// Your Twilio WhatsApp enabled phone number this is a different from twilio regular phone number
const twilioNumber = process.env.TWILIO_WHATSAPP_PHONE_NUMBER;

if (!mobileNumberProvidedByUser) {
console.error('Mobile number is missing');

//TODO: this can be improve by letting the AI Agent generate his/her own reply for the specific issue
_callback({
text: `Sorry there was an issue sending the WhatsApp message, please try again later`,
});
Expand All @@ -81,6 +79,7 @@ export const sendWhatsAppMessageAction: Action = {
if (!twilioNumber) {
console.error('Twilio WhatsApp number is missing');

//TODO: this can be improve by letting the AI Agent generate his/her own reply for the specific issue
_callback({
text: `Sorry there was an issue sending the WhatsApp message, please try again later`,
});
Expand All @@ -90,6 +89,7 @@ export const sendWhatsAppMessageAction: Action = {
if(messageToSendFromUser==null){
console.error('messageToSendFromUser is empty or null');

//TODO: this can be improve by letting the AI Agent generate his/her own reply for the specific issue
_callback({
text: `Sorry there was an issue sending the WhatsApp message, please try again later`,
});
Expand All @@ -107,8 +107,10 @@ export const sendWhatsAppMessageAction: Action = {
from: `whatsapp:${twilioNumber}`, // Your Twilio WhatsApp number
});

console.log("message body: ", message);
// for debug purposes uncomment this
console.log("check twilio message body: ", message);

//TODO: this can be improve by letting the AI Agent generate his/her own reply to user
const messageFromAgent = `WhatsApp message sent successfully to ${mobileNumberProvidedByUser}`;

// Call the callback to notify the user
Expand Down

0 comments on commit 026c821

Please sign in to comment.