Reputation: 23
I am using node js api for twilio to send outbound messages. I have a cron job going in google cloud which runs in each one minute. I am using a firestore function which triggered by the a pubsub topic. I send sms inside the firestore function.
I want to figure out how to control over the messages. I faced the issue and more than 10000 messages has been queued in twilio.
const client = require('twilio')(accountSid, authToken);
client.messages.create({
from: msgFromNum,
to: uNA.mobile_num,
body: uNA.message
})
.then(message => console.log(message.sid));
Upvotes: 2
Views: 63
Reputation: 1368
Once the messages are queued you can not stop sending it in Twilio. But you can set the validityPeriod for outbound messages. Also put some conditions before sending the message. As you have mentioned you are running cron job in 1mins. So Don't overload the messages in each minute.
The message can remain in outgoing queue for a maximum of 15 seconds after that it will be removed from queued messages.
async sendSms() {
const accountSid = 'AC****************************';
const authToken = '8b*****************************';
const client = require('twilio')(accountSid, authToken);
const msgFromNum = '+1*********';
const message = await client.messages.create({
from: msgFromNum,
to: '+1*********',
body: 'The message can remain in our outgoing queue for maximum 15 seconds.',
validityPeriod: 15 // in seconds
})
console.log(message.sid);
}
Upvotes: 1