Learn various filter combinations to build both simple and complex filter for only listening to certain Farcaster events.
Subscription filtering is used to decide what events an endpoint will receive based on the webhook event payload. The subscription filter is an enriched JSON syntax for both simple and complex filters (such as special logical and arithmetic operators $or, $gte, $eq).
This filter is used to validate simple JSON webhook payloads.
{"userId":"602"}
{"userId":"602",// Match userId with value "602""userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": ["0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],// ...Other fields}
This filter is used to validate nested webhook payloads.
Airstack webhooks filter only accept nested filters up to 3 levels. More than 3-level nesting will result in error.
{"socialCapital": {"socialCapitalRank":1 }}
{"socialCapital": {"socialCapitalScore":279,// match socialCapital.socialCapitalRank with exact value 1"socialCapitalRank":1 },"profileDisplayName":"dwr","profileImage":"https://i.imgur.com/Y1au7ZB.jpg",// ...Other fields}
{"userId":"3761","userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": [// Match with any result that contain the mentioned address// in the array"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],// ...Other fields}
Complex filters contain more logic such as logical operators and special operators. Complex filters are employed to filter events using one or more conditions, e.g., $or logical operator filter.
This filter matches event which directly does not match the event type in the webhook payload.
{"userId": {"$neq":"1" }}
{// Match with any payload that doesn't have userId value 1"userId":"602","userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": ["0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],// ...Other fields}
{// Match either the userId value or userAddress value"userId":"602","userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": ["0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],// ...Other fields}
$and
This filter is used to match multiple conditions evaluated using AND logic as defined in the schema. This can also be combined with other operators such as $or.
This filter is used to match keys where the value can be a range of values. It can be used in place of $or if you are comparing on the same field. The opposite of this operator $nin can be used to match keys where the value is not in a range of values.
{"userId": {"$in": ["602","2602"] }}
{"userId":"602",// 602 is inside the $in operator"userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": ["0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],"socialCapital": {"socialCapitalRank":70,"socialCapitalScore":100 },// ...Other fields}
These filters match events based on arithmetic operators. For example, the filter below will match all events where the age is greater than 1. The operators supported are $gt, $gte, $lt, $lte
{"socialCapital": {"socialCapitalScore":279,// Only match payload with socialCapital.socialCapitalRank <= 100"socialCapitalRank":1 },"profileDisplayName":"dwr","profileImage":"https://i.imgur.com/Y1au7ZB.jpg",// ...Other fields}
{"socialCapital": {"socialCapitalScore":279,// Only match payload with socialCapital.socialCapitalRank <= 100"socialCapitalRank":1 },"profileDisplayName":"dwr","profileImage":"https://i.imgur.com/Y1au7ZB.jpg",// ...Other fields}
These filters match events with payloads that match the supplied regex.
{"profileName": {"$regex":"^betashop" }}
{// Match with profileName that starts with "betashop""profileName":"betashop.eth","userId":"602","userAddress":"0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","userAssociatedAddresses": ["0xa3a736379bfb4a9748c3e4daf5f9af0edfcc6c1a","Cry3MBYMS34p67Tr6pmart85JuTpdULhgDtaV8rxadng","0xcbfbcbfca74955b8ab75dec41f7b9ef36f329879" ],// ...Other fields}
Developer Support
If you have any questions or need help regarding defining custom filters for your use cases, please join our Airstack's Telegram group.