

# Receiving caller input for the Amazon Chime SDK PSTN audio service
<a name="case-4"></a>

You use the `ReceiveDigits` action to collect inbound DTMF digits and match them against a regular expression. When the SIP media application receives digits that match the regular expression, it invokes a AWS Lambda function with an `ACTION_SUCCESSFUL` event. The collected digits appear in the `ReceivedDigits` value in the `ActionData` object.

For example:

```
{
    "SchemaVersion": "1.0",
    "Sequence": 4,
    "InvocationEventType": "ACTION_SUCCESSFUL",
    "ActionData": {
        "ReceivedDigits": "",
        "Type": "ReceiveDigits",
        "Parameters": {
            "CallId": "{{call-id-1}}",
            "InputDigitsRegex": "{{^\d{2}#$}}",
            "InBetweenDigitsDurationInMilliseconds": {{5000}},
            "FlushDigitsDurationInMilliseconds": {{10000}}
        }
    },
    "CallDetails": {
        "TransactionId": "{{transaction-id}}",
        "AwsAccountId": "{{aws-account-id}}",
        "AwsRegion": "{{us-east-1}}",
        "SipRuleId": "{{sip-rule-id}}",
        "SipApplicationId": "{{sip-application-id}}",
        "Participants": [
            {
                "CallId": "{{call-id-1}}",
                "ParticipantTag": "LEG-A",
                "To": "{{+12065551212}}",
                "From": "{{+15105550101}}",
                "Direction": "Inbound",
                "StartTimeInMilliseconds": "{{159700958834234}}",
                "Status": "Connected"
            }
        ]
    }
}
```

Once the caller enters digits that match your regular expression pattern, the SIP media application invokes an AWS Lambda function that returns the following type of payload:

```
{
    "SchemaVersion": "1.0",
    "Sequence": 5,
    "InvocationEventType": "DIGITS_RECEIVED",
    "ActionData": {
        "ReceivedDigits": "{{11#}}",
        "Type": "ReceiveDigits",
        "Parameters": {
            "CallId": "{{call-id-1}}",
            "InputDigitsRegex": "{{^\d{2}#$}}",
            "InBetweenDigitsDurationInMilliseconds": {{5000}},
            "FlushDigitsDurationInMilliseconds": {{10000}}
        }
    },
    "CallDetails": {
        "TransactionId": "{{transaction-id}}",
        "AwsAccountId": "{{aws-account-id}}",
        "AwsRegion": "{{us-east-1}}",
        "SipRuleId": "{{sip-rule-id}}",
        "SipApplicationId": "{{sip-application-id}}",
        "Participants": [
            {
                "CallId": "{{call-id-1}}",
                "ParticipantTag": "LEG-A",
                "To": "{{+12065551212}}",
                "From": "{{+15105550101}}",
                "Direction": "Inbound",
                "StartTimeInMilliseconds": "{{159700958834234}}",
                "Status": "Connected"
            }
        ]
    }
}
```

See a working example on GitHub: [https://github.com/aws-samples/amazon-chime-sma-on-demand-recording](https://github.com/aws-samples/amazon-chime-sma-on-demand-recording)