Support TWILIO_SENDER_SID override before sender lookup
This commit is contained in:
20
src/index.ts
20
src/index.ts
@@ -465,8 +465,16 @@ async function ensureFunnel(port: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findWhatsappSenderSid(client: ReturnType<typeof createClient>, from: string) {
|
async function findWhatsappSenderSid(
|
||||||
// Fetch sender SID that matches configured WhatsApp from number.
|
client: ReturnType<typeof createClient>,
|
||||||
|
from: string,
|
||||||
|
explicitSenderSid?: string
|
||||||
|
) {
|
||||||
|
// Use explicit sender SID if provided, otherwise list and match by sender_id.
|
||||||
|
if (explicitSenderSid) {
|
||||||
|
logVerbose(`Using TWILIO_SENDER_SID from env: ${explicitSenderSid}`);
|
||||||
|
return explicitSenderSid;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const resp = await (client as unknown as TwilioRequester).request({
|
const resp = await (client as unknown as TwilioRequester).request({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@@ -486,10 +494,12 @@ async function findWhatsappSenderSid(client: ReturnType<typeof createClient>, fr
|
|||||||
return match.sid;
|
return match.sid;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(danger('Unable to list WhatsApp senders via Twilio API.'));
|
console.error(danger('Unable to list WhatsApp senders via Twilio API.'));
|
||||||
if (globalVerbose) console.error(err);
|
if (globalVerbose) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
console.error(
|
console.error(
|
||||||
info(
|
info(
|
||||||
'Provide TWILIO_SENDER_SID in .env to skip lookup (find it in Twilio Console → Messaging → Senders → WhatsApp).'
|
'Set TWILIO_SENDER_SID in .env to skip discovery (Twilio Console → Messaging → Senders → WhatsApp).'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -709,7 +719,7 @@ program
|
|||||||
|
|
||||||
// Configure Twilio sender webhook
|
// Configure Twilio sender webhook
|
||||||
const client = createClient(env);
|
const client = createClient(env);
|
||||||
const senderSid = await findWhatsappSenderSid(client, env.whatsappFrom);
|
const senderSid = await findWhatsappSenderSid(client, env.whatsappFrom, env.whatsappSenderSid);
|
||||||
await updateWebhook(client, senderSid, publicUrl, 'POST');
|
await updateWebhook(client, senderSid, publicUrl, 'POST');
|
||||||
|
|
||||||
console.log('\nSetup complete. Leave this process running to keep the webhook online. Ctrl+C to stop.');
|
console.log('\nSetup complete. Leave this process running to keep the webhook online. Ctrl+C to stop.');
|
||||||
|
|||||||
Reference in New Issue
Block a user