- Newest
- Most votes
- Most comments
Yes, there are ways to retrieve the actual phone number of the caller in Amazon Connect, but the SearchContactsCommand method you're currently using doesn't directly provide this information in the output you've shown.
To get the caller's phone number, you have a couple of options:
-
Use the GetContactAttributes API: This API allows you to retrieve additional attributes associated with a contact, which may include the caller's phone number. You would need to use the contact ID (which appears to be what you have in the ContactNumber field) to make this request.
-
Use the DescribeContact API: This API provides detailed information about a specific contact, including the customer endpoint information which should contain the phone number for voice contacts.
-
If you're working within the Amazon Connect Agent Workspace, you can use the getPhoneNumber function. This function returns the voice contact's phone number they are calling from. However, this is specific to the Agent Workspace environment and requires the Contact.CustomerDetails.View permission.
-
When setting up your contact flows in Amazon Connect, you can store the caller's phone number as a contact attribute. Then, you can retrieve this information using the GetContactAttributes API mentioned earlier.
It's important to note that the availability of the phone number may depend on how your Amazon Connect instance is configured and what information is being captured and stored during the call.
If you're unable to retrieve the phone number through these methods, you might need to adjust your Amazon Connect configuration to ensure this information is being captured and made available through the APIs.
Remember to handle this information securely, as phone numbers are considered personally identifiable information (PII).
Sources
Get the phone number of the contact in Amazon Connect Agent Workspace - Agent Workspace
Contact - Amazon Connect
Yes, you can retrieve the caller's phone number, but you're right — SearchContactsCommand doesn't include it directly.
Here's what to do: Use DescribeContactCommand from the same SDK.
Once you have the ContactId (looks like you already do from SearchContactsCommand), you can run:
js Copy Edit import { ConnectClient, DescribeContactCommand } from "@aws-sdk/client-connect";
const client = new ConnectClient({ region: "your-region" });
const command = new DescribeContactCommand({ InstanceId: "your-instance-id", ContactId: "0f9c395f-d0b0-4f71-b846-c54958713198" });
const response = await client.send(command); console.log(response.Contact?.CustomerEndpoint?.Address); // This is the caller’s phone number Alternatively, if your contact flow saves the caller’s number as an attribute (e.g., using Set contact attributes block), you can use:
js Copy Edit import { GetContactAttributesCommand } from "@aws-sdk/client-connect";
const getAttrCommand = new GetContactAttributesCommand({ InstanceId: "your-instance-id", InitialContactId: "0f9c395f-d0b0-4f71-b846-c54958713198" });
const attrResponse = await client.send(getAttrCommand); console.log(attrResponse.Attributes?.["CustomerNumber"]); ✅ Note: CustomerEndpoint.Address is only available if the customer called directly into your Amazon Connect instance (not transferred from another system).
Let me know if you want a code sample in Python or need help setting up permissions!
answered a year ago
