Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Deleting pending requests in Javascript

I have created an API using a code ready made from a twilio blog post which I have modified. The code's use is to parse an incoming mail that is sent to "anything"@parse."mydomain".gr and forward it to a mobile number as an sms message. The problem is that if a mail cannot be forwarded for some reason (e.g. text body is more than 1600 characters) it keeps trying and sends error messages in the logs, or sends the messages long after the actual email was forwarded. So I was wondering if it is possible to delete requests already made, and/or "drop" future requests if not successfully fulfilled after say 10000ms. Also I would like to know if I can see the "pending" requests that exist right now somehow. Below is the code I am using.

const util = require('util');
const multer = require('multer');
const addrs = require("email-addresses");
const twilio = require('twilio');
//rev.1 
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
//end rev.1

module.exports = async (req, res) => { 
const client = twilio(process.env.TWILIO_ACCOUNT_SID,process.env.TWILIO_AUTH_TOKEN);
await util.promisify(multer().any())(req, res);

const from = req.body.from;
const to = req.body.to;
const subject = req.body.subject;
const body = req.body.text;

//Using email-addresses library to extract email details.
const toAddress = addrs.parseOneAddress(to);
const toName = toAddress.local;
const fromAddress = addrs.parseOneAddress(from);
const fromName = fromAddress.local;

//Sending SMS with Twilio Client
client.messages.create({
    to: '<mynumber>',
    from: process.env.TWILIO_PHONE_NUMBER,
    body: `Message from:${fromName}\n${body}`
}).then(msg => {
    console.log(msg)
    res.status(200).send(msg.sid);
}).catch(err => {
    console.log(err);
});
//rev.1
//define cancelation function 

function cancelation () {
   client.messages(msg.sid)
  .update({status: 'canceled'})
  .then(message => console.log(message.to));
};

//execute cancelation after 10000 milliseconds (10 seconds)
setTimeout(cancelation, 10000); 

//define delete_message function 

function message_delete () {
    client.messages(msg.sid).remove();  
}

//execute cancelation after 10000 milliseconds (10 seconds)
setTimeout(message_delete, 10000); 
//end rev.1
};
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda