Why does a text filter extension receive the ISO Country Code, but not the text server?

The documentation for a text filter extension states that receiverISOCountryCode is a field the extension receives

https://developer.apple.com/documentation/sms_and_call_reporting/ilmessagefilterqueryrequest/3979257-receiverisocountrycode

"The ISO Country Code of the receiving phone number"

However, if the extension defers to its text server, then the payload sent to the server doesn't contain the iso country code:

 POST /server-endpoint HTTP/1.1
Accept: */*
Content-Type: application/json; charset=utf-8
Content-Length: 148
{
    "_version": 1,
    "query": {
        "sender": "14085550001",
        "message": {
            "text": "This is a message"
        }
    },
    "app": {
        "version": "1.1"
    }
}

from: https://developer.apple.com/documentation/sms_and_call_reporting/ilmessagefilterextensioncontext/2880240-deferqueryrequesttonetwork

Why does the payload sent to the text server not contain the country code?

The absence of the receiverISOCountryCode field in the payload sent to the text server through the deferQueryRequestToNetwork method appears to be by design, reflecting a deliberate choice by Apple to limit the data being transmitted for reasons such as privacy or simplicity. Here's an explanation:

  1. Privacy Considerations
    Apple tends to minimize the amount of potentially sensitive user data transmitted to external servers. Including the ISO country code could inadvertently expose information about the recipient's location, which may not be necessary for the text server's logic.

  2. Data Minimization Principle
    By omitting the ISO country code, Apple adheres to the principle of transmitting only essential information to reduce risks and comply with privacy regulations like GDPR. The deferQueryRequestToNetwork payload likely prioritizes fields that are strictly necessary for spam filtering or other server-side logic.

  3. Server-Side Independence
    The deferQueryRequestToNetwork payload is designed to allow the server to independently interpret the context of the query. The server may already have alternative ways of determining the ISO country code if needed, such as through metadata, IP-based geolocation, or pre-established associations with the user's profile.

  4. Extension Context Responsibility
    The receiverISOCountryCode field is part of the ILMessageFilterQueryRequest object provided to the app extension. The extension has access to this data and is expected to handle country-specific filtering logic locally. If the extension defers to the server, it does so with a reduced data set, likely because it assumes the server doesn't require the country code or has alternative means to determine context.


How to Handle This in Your Implementation

If your server requires the receiverISOCountryCode to perform its filtering logic:

  • Modify the extension logic to include the ISO country code in the deferred request's payload before transmitting it.
  • For example, you can enrich the payload within the deferQueryRequestToNetwork method by appending the receiverISOCountryCode explicitly to the query or app fields.

Example:

let isoCountryCode = request.receiverISOCountryCode
let enrichedPayload: [String: Any] = [
    "_version": 1,
    "query": [
        "sender": request.sender,
        "message": [
            "text": request.messageBody
        ],
        "receiverISOCountryCode": isoCountryCode
    ],
    "app": [
        "version": "1.1"
    ]
]
// Send this payload to the server.

This approach allows you to balance between Apple's default payload structure and the specific requirements of your text server.

You just said Apple omit it from the payload for privacy reasons, then go on to propose explicity adding it, which would negate the very reason Apple omitted it.

However, its not possible to modify the payload anyway, it is transmitted by the OS and the extension does not have the opportunity to change it.

Why does a text filter extension receive the ISO Country Code, but not the text server?
 
 
Q