@@ -71,7 +71,9 @@ const protectedData = await dataProtectorCore.protectData({
7171
7272Grant permission for a sender and/or an app to contact the user.
7373
74- ``` ts twoslash
74+ ::: code-group
75+
76+ ``` ts twoslash [Single Message]
7577import { IExecDataProtectorCore , getWeb3Provider } from ' @iexec/dataprotector' ;
7678const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
7779const dataProtectorCore = new IExecDataProtectorCore (web3Provider );
@@ -85,11 +87,47 @@ const grantedAccess = await dataProtectorCore.grantAccess({
8587});
8688```
8789
90+ ``` ts twoslash [Bulk Campaigns]
91+ import { IExecDataProtectorCore , getWeb3Provider } from ' @iexec/dataprotector' ;
92+ const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
93+ const dataProtectorCore = new IExecDataProtectorCore (web3Provider );
94+
95+ // For bulk campaigns, recipients must grant access with allowBulk: true
96+ const grantedAccess = await dataProtectorCore .grantAccess ({
97+ protectedData: ' 0x123abc...' ,
98+ authorizedApp: ' 0x456def...' ,
99+ authorizedUser: ' 0x789cba...' ,
100+ allowBulk: true , // [!code focus] Enable bulk processing
101+ });
102+ ```
103+
104+ :::
105+
106+ ::: info
107+
108+ Setting ` allowBulk: true ` automatically configures ` pricePerAccess ` to ` 0 ` and
109+ ` numberOfAccess ` to ` Number.MAX_SAFE_INTEGER ` , enabling unlimited bulk
110+ processing at no cost per access.
111+
112+ :::
113+
88114## 4. Send the Message
89115
116+ You can send messages in two modes:
117+
118+ - ** Single Processing** : Send to one recipient using ` sendEmail ` or
119+ ` sendTelegram `
120+ - ** Bulk Processing** : Send the same message to multiple recipients efficiently
121+ using ` prepareEmailCampaign ` + ` sendEmailCampaign ` or
122+ ` prepareTelegramCampaign ` + ` sendTelegramCampaign `
123+
124+ ### Single Message Processing
125+
126+ Send a message to a single recipient:
127+
90128::: code-group
91129
92- ``` ts twoslash [Web3Mail]
130+ ``` ts twoslash [Web3Mail - Single ]
93131import { IExecWeb3mail , getWeb3Provider } from ' @iexec/web3mail' ;
94132
95133const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
@@ -99,11 +137,10 @@ const sendEmail = await web3mail.sendEmail({
99137 protectedData: ' 0x123abc...' ,
100138 emailSubject: ' My email subject' ,
101139 emailContent: ' My email content' ,
102- // useVoucher: true,
103140});
104141```
105142
106- ``` ts twoslash [Web3Telegram]
143+ ``` ts twoslash [Web3Telegram - Single ]
107144import { IExecWeb3telegram , getWeb3Provider } from ' @iexec/web3telegram' ;
108145
109146const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
@@ -118,6 +155,88 @@ const sendTelegram = await web3telegram.sendTelegram({
118155
119156:::
120157
158+ ### Bulk Message Processing
159+
160+ Send the same message to multiple recipients efficiently in a single
161+ transaction.
162+
163+ ** How it works:**
164+
165+ 1 . ** Fetch contacts** with bulk access capability using ` fetchMyContacts ` or
166+ ` fetchUserContacts ` with ` bulkOnly: true `
167+ 2 . ** Prepare the campaign** using ` prepareEmailCampaign ` or
168+ ` prepareTelegramCampaign ` to create a bulk request
169+ 3 . ** Send the campaign** using ` sendEmailCampaign ` or ` sendTelegramCampaign ` to
170+ process the bulk request
171+
172+ ::: warning Prerequisites
173+
174+ Before using bulk processing, ensure that recipients have granted access with
175+ ` allowBulk: true ` when calling ` grantAccess ` (see step 3 above).
176+
177+ :::
178+
179+ ::: code-group
180+
181+ ``` ts twoslash [Web3Mail - Bulk]
182+ import { IExecWeb3mail , getWeb3Provider } from ' @iexec/web3mail' ;
183+
184+ const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
185+ const web3mail = new IExecWeb3mail (web3Provider );
186+
187+ // Step 1: Fetch contacts with bulk access
188+ const contacts = await web3mail .fetchMyContacts ({ bulkOnly: true });
189+ const grantedAccessArray = contacts .map ((contact ) => contact .grantedAccess );
190+
191+ // Step 2: Prepare the campaign
192+ const emailCampaign = await web3mail .prepareEmailCampaign ({
193+ grantedAccess: grantedAccessArray ,
194+ emailSubject: ' Hello from My Awesome App!' ,
195+ emailContent: ' Hello! This is a bulk email sent to all recipients.' ,
196+ contentType: ' text/html' ,
197+ });
198+
199+ // Step 3: Send the bulk campaign
200+ const result = await web3mail .sendEmailCampaign ({
201+ campaignRequest: emailCampaign .campaignRequest ,
202+ });
203+
204+ console .log (` Campaign sent! Created ${result .tasks .length } tasks ` );
205+ ```
206+
207+ ``` ts twoslash [Web3Telegram - Bulk]
208+ import { IExecWeb3telegram , getWeb3Provider } from ' @iexec/web3telegram' ;
209+
210+ const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
211+ const web3telegram = new IExecWeb3telegram (web3Provider );
212+
213+ // Step 1: Fetch contacts with bulk access
214+ const contacts = await web3telegram .fetchMyContacts ({ bulkOnly: true });
215+ const grantedAccessArray = contacts .map ((contact ) => contact .grantedAccess );
216+
217+ // Step 2: Prepare the campaign
218+ const telegramCampaign = await web3telegram .prepareTelegramCampaign ({
219+ grantedAccess: grantedAccessArray ,
220+ telegramContent: ' Hello! This is a bulk message sent to all recipients.' ,
221+ senderName: ' My Awesome App' ,
222+ });
223+
224+ // Step 3: Send the bulk campaign
225+ const result = await web3telegram .sendTelegramCampaign ({
226+ campaignRequest: telegramCampaign .campaignRequest ,
227+ });
228+
229+ console .log (` Campaign sent! Created ${result .tasks .length } tasks ` );
230+ ```
231+
232+ :::
233+
234+ ** Benefits:**
235+
236+ - Lower costs: fewer transactions reduce gas fees
237+ - Higher performance: multiple recipients processed in parallel
238+ - Better scalability: efficiently handle hundreds or thousands of recipients
239+
121240## Payment
122241
123242Each message sent through Web3Mail or Web3Telegram requires payment in RLC
0 commit comments