How to get the caller's phone number for inbound calls

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

I’m creating inbound agents. How can I capture the caller’s phone number? Is there a way to pass it in dispatch metadata?

When a caller joins a room by making a phone call, they become a participant with a sip.phoneNumber attribute. You can access this from the participant’s attributes field.

You cannot put the caller’s phone number in the dispatch rule metadata because the dispatch rule is created before any call is received. Unless you know you’ll only get calls from one specific phone number, you can’t pre-populate this in the dispatch rule.