Learn how to build a primary inbox that only includes messages from known senders.
The Primary Inbox should contain all the users that a given user certainly knows.
Some criteria that can be checked for a user to be included in the primary inbox are:
Senders is followed by the user on Lens
Senders is followed by the user on Farcaster
The user has sent tokens to the Sender
If the sender meets none of the listed criteria, they should be removed from the primary inbox and then checked to see if they belong in the General Inbox.
Additionally, you can use XMTP Consent to check if a sender has given consent (has an Allowed consent value) to the sender before including them in the primary inbox. By default, you should place all senders that have been given consent directly into the Primary Inbox.
As demonstrated below, your app's interface can also feature user-friendly options for users to apply consent or deny consent.
Table Of Contents
In this guide, you will learn how to use Airstack to build an XMTP primary inbox by:
Airstack provides an AI solution for you to build GraphQL queries to fulfill your use case easily. You can find the AI prompt of each query in the demo's caption or title for yourself to try.
Best Practice
While choosing a specific criteria will significantly decrease the number of spam appearing on your user's XMTP inbox, It is best practice that you combine the multiple criterion given here to build your Primary Inbox.
This is done to provide multiple layers of filtration that will make it nearly impossible for spammers to have their messages slide into your users' XMTP inbox.
Check If A Given User Is Following Senders on Lens
You can check if a given user is following senders on Lens by providing an array of senders' 0x addresses to the $senders variable and the main user to the $mainUser variable using the Wallet API:
You can use this query to filter senders on the fly with a maximum of 200 wallet inputs to the $senders variable per API call.
{"data": {"Wallet": {"socialFollowers": {"Follower": [ {"dappName":"lens","followingAddress": {"addresses": [// main user is following this XMTP user on Lens"0x0964256674e42d61f0ff84097e28f65311786ccb" ] } }, {"dappName":"lens","followingAddress": {"addresses": [// main user is following this XMTP user on Lens"0xb59aa5bb9270d44be3fa9b6d67520a2d28cf80ab" ] } } ] } } }}
Check If A Given User Is Following Senders on Farcaster
You can check if a given user is following senders on Farcaster by providing an array of senders' 0x addresses to the $senders variable and the main user to the $mainUser variable using the Wallet API:
You can use this query to filter senders on the fly with a maximum of 200 wallet inputs to the $senders variable per API call.
{"data": {"Wallet": {"socialFollowers": {"Follower": [ {"dappName":"farcaster","followingAddress": {"addresses": ["0x40ceb58e8f17ae4fa6124684aaad22a39c33fb8c",// The main user follow this XMTP user on Farcaster"0xb59aa5bb9270d44be3fa9b6d67520a2d28cf80ab" ] } }, {"dappName":"farcaster","followingAddress": {"addresses": ["0xe1b1e3bbf4f29bd7253d6fc1e2ddc9cacb0a546a",// The main user follow this XMTP user on Farcaster"0x0964256674e42d61f0ff84097e28f65311786ccb" ] } }, {"dappName":"farcaster","followingAddress": {"addresses": ["0x6b0bda3f2ffed5efc83fa8c024acff1dd45793f1",// The main user follow this XMTP user on Farcaster"0xd7029bdea1c17493893aafe29aad69ef892b8ff2",// Other Farcaster connected addresses ] } } ] } } }}
Check If A Given User Has Sent Tokens To Senders
You can check if a given user has sent any tokens to the senders on either Ethereum, Polygon, Base, or Zora by providing an array of senders' 0x addresses to the $senders variable and the main user to the $mainUser variable using the TokenTransfers API:
Try Demo
Code
You can use this query to filter senders on the fly with a maximum of 200 wallet inputs to the $senders variable per API call.
{"data": {"ethereum": {"TokenTransfer": [ {"to": {"addresses": ["0xb59aa5bb9270d44be3fa9b6d67520a2d28cf80ab" ] } },// ...Other token transfers// If other senders' addresses, does not appear,// then the main user never sent any tokens to those senders ] },"polygon": {// no transfers from the main user to senders on Polygon"TokenTransfer":null },"base": {// no transfers from the main user to senders on Base"TokenTransfer":null },"zora": {// no transfers from the main user to senders on Zora"TokenTransfer":null } }}
Developer Support
If you have any questions or need help regarding creating a primary inbox for your XMTP messaging app, please join our Airstack's Telegram group.