send message to new recipient
This commit is contained in:
@ -1,16 +1,37 @@
|
||||
import { BlitzApiRequest, BlitzApiResponse } from "blitz";
|
||||
|
||||
import db from "db";
|
||||
import twilio from "twilio";
|
||||
|
||||
export default async function ddd(req: BlitzApiRequest, res: BlitzApiResponse) {
|
||||
await Promise.all([
|
||||
/*await Promise.all([
|
||||
db.message.deleteMany(),
|
||||
db.phoneCall.deleteMany(),
|
||||
db.phoneNumber.deleteMany(),
|
||||
db.customer.deleteMany(),
|
||||
]);
|
||||
|
||||
await db.user.deleteMany();
|
||||
await db.user.deleteMany();*/
|
||||
const accountSid = "ACa886d066be0832990d1cf43fb1d53362";
|
||||
const authToken = "8696a59a64b94bb4eba3548ed815953b";
|
||||
/*const ddd = await twilio(accountSid, authToken)
|
||||
.lookups
|
||||
.v1
|
||||
// .phoneNumbers("+33613370787")
|
||||
.phoneNumbers("+33476982071")
|
||||
.fetch();*/
|
||||
try {
|
||||
await twilio(accountSid, authToken).messages.create({
|
||||
body: "content",
|
||||
to: "+213744123789",
|
||||
from: "+33757592025",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error.code);
|
||||
console.log(error.moreInfo);
|
||||
console.log(error.details);
|
||||
// console.log(JSON.stringify(Object.keys(error)));
|
||||
}
|
||||
|
||||
res.status(200).end();
|
||||
res.status(200).send(ddd);
|
||||
}
|
||||
|
@ -16,15 +16,24 @@ const sendMessageQueue = Queue<Payload>(
|
||||
const customer = await db.customer.findFirst({ where: { id: customerId } });
|
||||
const phoneNumber = await db.phoneNumber.findFirst({ where: { customerId } });
|
||||
|
||||
const message = await twilio(customer!.accountSid!, customer!.authToken!).messages.create({
|
||||
body: content,
|
||||
to,
|
||||
from: phoneNumber!.phoneNumber,
|
||||
});
|
||||
await db.message.update({
|
||||
where: { id },
|
||||
data: { twilioSid: message.sid },
|
||||
});
|
||||
try {
|
||||
const message = await twilio(
|
||||
customer!.accountSid!,
|
||||
customer!.authToken!
|
||||
).messages.create({
|
||||
body: content,
|
||||
to,
|
||||
from: phoneNumber!.phoneNumber,
|
||||
});
|
||||
await db.message.update({
|
||||
where: { id },
|
||||
data: { twilioSid: message.sid },
|
||||
});
|
||||
} catch (error) {
|
||||
// TODO: handle twilio error
|
||||
console.log(error.code); // 21211
|
||||
console.log(error.moreInfo); // https://www.twilio.com/docs/errors/21211
|
||||
}
|
||||
},
|
||||
{
|
||||
retry: ["1min"],
|
||||
|
Reference in New Issue
Block a user