2
votes

When sending SMS to Twilio, Twilio sends several requests to a specified URL to give a status of that SMS delivery through webhooks. I want to make this callback asynchronous, so I developed a Cloud Function that sends a representation of the request to a Cloud Task that itself reach a dedicated endpoint of my app that recreate and simulate the Twilio request internally.

Twilio signs his requests using:

  • my twilio account's secret key
  • the absolute URL that it reaches out
  • and the body of his request

So on my backend, I should know which endpoint Twilio reached out initially. I want to do it inside the Cloud Function, and I want to do it programmatically because this "asynchronous webhook" is also used when people answers to SMS.

The current URL of my webhook has the following format:

https://<location>-<project>.cloudfunctions.net/<cloud function name>/<some SMS uuid>

The current payload sent to my Cloud Task is the following:

absoluteUri: req.protocol + '://' + req.hostname + req.originalUrl,
relativeUri: req.originalUrl,
queryParams: req.query,
headers: req.headers,
body: req.body,

The problem is that req.originalUrl do not contain the full URI, my absoluteUri is currently:

https://<location>-<project>.cloudfunctions.net/<some SMS uuid>

So here is my question: inside a Cloud Function, is there a way to get its name programmatically?

1

1 Answers

0
votes

As the Cloud Function name is the entry point and should be hardcoded, I ended up writing a deploy script that sed some placeholder.

Looks very ugly, if you have a better way it will be welcome.