In twilio's API, you can assign numbers to a messaging service, and you can set incoming/status-callback URLs on both the number and the messaging service. For a number in a messaging service, which URL gets picked if both are set?
Apologies if the documentation lays it out somewhere, I dove through 3 or 4 pages of docs trying to find this answer.
Great question. When a Sender like a phone number is added to a Messaging Service, the Messaging Service will handle the webhooks according to its Integration configuration. You can configure this behavior by going to the Integration page of your Messaging Service, and selecting one of the radio buttons under Incoming Messages.
By default, a conversation will be automatically created, and the incoming message webhook configured on the Sender will not be called.
You can configure the webhook to be called for all senders in the Messaging Service by selecting Send a webhook.
Select Defer to sender's webhook if you want the incoming message webhook of the sender to be triggered.
Under the Integration page, there's also a Delivery Status Callback field. If you fill out this field, you'll receive webhook requests for the outgoing message delivery status, if you don't provide a status callback URL on the individual message. If a status callback URL is configured on the individual message, only that URL will be triggered.
Here's a sample where the status callback URL is configured on the individual message:
twilio api:core:messages:create --to +1234567890 `
--status-callback https://myhost/message-status-callback `
--messaging-service-sid MG*** `
--body Ahoy
While I have a status callback URL (https://myhost/messaging-service-status-callback
) configured on the Messaging Service above, it is ignored and https://myhost/message-status-callback
is called.
When I omit the status callback URL on the message like this:
twilio api:core:messages:create --to +1234567890 `
--messaging-service-sid MG*** `
--body Ahoy
The status callback URL on my Messaging Service is called: https://myhost/messaging-service-status-callback
.