@@ -18,7 +18,11 @@ flow is the same, except that:
18181 . (Telegram only) Get a Chat ID from the iExec bot
19192 . Create the Protected Data using DataProtector Toolkit
20203 . Grant access of your Protected Data
21- 4 . Send the message using the relevant SDK ( Web3Mail / Web3Telegram )
21+ 4 . Send the message using the relevant SDK (Web3Mail / Web3Telegram)
22+
23+ You can send messages in two modes: single messages (one recipient at a time) or
24+ bulk campaigns (same message to multiple recipients efficiently). See step 4
25+ below for details.
2226
2327## 1. Retrieve the Telegram Chat ID (Telegram only)
2428
@@ -69,7 +73,9 @@ const protectedData = await dataProtectorCore.protectData({
6973
7074## 3. Grant Access
7175
72- Grant permission for a sender and/or an app to contact the user.
76+ Grant permission for a sender and/or an app to contact the user. Choose the mode
77+ based on your use case: use ** Single Message** mode for individual messages, or
78+ ** Bulk Campaigns** mode for sending the same message to multiple recipients.
7379
7480::: code-group
7581
@@ -92,37 +98,20 @@ import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector';
9298const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
9399const dataProtectorCore = new IExecDataProtectorCore (web3Provider );
94100// ---cut---
95- // For bulk campaigns, recipients must grant access with allowBulk: true
101+ // allowBulk: true automatically sets pricePerAccess to 0 and numberOfAccess to unlimited
96102const grantedAccess = await dataProtectorCore .grantAccess ({
97103 protectedData: ' 0x123abc...' ,
98104 authorizedApp: ' 0x456def...' ,
99105 authorizedUser: ' 0x789cba...' ,
100- allowBulk: true , // [!code focus] Enable bulk processing
106+ allowBulk: true , // [!code focus]
101107});
102108```
103109
104110:::
105111
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-
114112## 4. Send the Message
115113
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 a two-step process: first call ` prepareEmailCampaign ` or
122- ` prepareTelegramCampaign ` to prepare the campaign, then call
123- ` sendEmailCampaign ` or ` sendTelegramCampaign ` to send it
124-
125- ### Single Message Processing
114+ ### Single Messages
126115
127116Send a message to a single recipient:
128117
@@ -156,10 +145,12 @@ const sendTelegram = await web3telegram.sendTelegram({
156145
157146:::
158147
159- ### Bulk Message Processing
148+ ### Bulk Campaigns
160149
161- Send the same message to multiple recipients efficiently in a single
162- transaction.
150+ Send the same message to multiple recipients efficiently. Bulk processing groups
151+ multiple protected data items (emails for Web3Mail or chat IDs for Web3Telegram)
152+ together, reducing gas fees and processing recipients in parallel across one or
153+ more transactions.
163154
164155** To send a bulk campaign, follow these steps in order:**
165156
@@ -169,8 +160,7 @@ transaction.
169160 ` prepareTelegramCampaign ` (for Web3Telegram). This creates a bulk request
170161 object that groups all recipients together
1711623 . ** Send the campaign** by calling ` sendEmailCampaign ` (for Web3Mail) or
172- ` sendTelegramCampaign ` (for Web3Telegram) with the prepared bulk request.
173- This processes all recipients in one or more efficient transactions
163+ ` sendTelegramCampaign ` (for Web3Telegram) with the prepared bulk request
174164
175165::: warning Prerequisites
176166
@@ -182,60 +172,92 @@ Before using bulk processing, ensure that recipients have granted access with
182172::: code-group
183173
184174``` ts twoslash [Web3Mail - Bulk]
185- import { IExecWeb3mail , getWeb3Provider } from ' @iexec/web3mail' ;
175+ import { IExecDataProtectorCore , getWeb3Provider } from ' @iexec/dataprotector' ;
176+ import { IExecWeb3mail } from ' @iexec/web3mail' ;
186177
187178const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
179+ const dataProtectorCore = new IExecDataProtectorCore (web3Provider );
188180const web3mail = new IExecWeb3mail (web3Provider );
189181
190- // Step 1: Fetch contacts with bulk access
182+ // Steps 1-2: Executed by the recipient (protected data provider)
183+ // Step 1: Create Protected Data (see section 2)
184+ const protectedData = await dataProtectorCore .protectData ({
185+ data: {
186+ 187+ },
188+ });
189+
190+ // Step 2: Grant access with bulk processing enabled (see section 3)
191+ const grantedAccess = await dataProtectorCore .grantAccess ({
192+ protectedData: protectedData .address ,
193+ authorizedApp: ' 0x456def...' ,
194+ authorizedUser: ' 0x789cba...' ,
195+ allowBulk: true ,
196+ });
197+
198+ // Steps 3-5: Executed by the sender (who wants to contact recipients)
199+ // Step 3: Fetch contacts with bulk access
191200const contacts = await web3mail .fetchMyContacts ({ bulkOnly: true });
192201const grantedAccessArray = contacts .map ((contact ) => contact .grantedAccess );
193202
194- // Step 2 : Prepare the campaign
203+ // Step 4 : Prepare the campaign
195204const emailCampaign = await web3mail .prepareEmailCampaign ({
196205 grantedAccesses: grantedAccessArray ,
197206 emailSubject: ' Hello from My Awesome App!' ,
198207 emailContent: ' Hello! This is a bulk email sent to all recipients.' ,
199208 contentType: ' text/html' ,
200209});
201210
202- // Step 3 : Send the bulk campaign
211+ // Step 5 : Send the bulk campaign
203212const { tasks } = await web3mail .sendEmailCampaign ({
204213 campaignRequest: emailCampaign .campaignRequest ,
205214});
206215```
207216
208217``` ts twoslash [Web3Telegram - Bulk]
209- import { IExecWeb3telegram , getWeb3Provider } from ' @iexec/web3telegram' ;
218+ import { IExecDataProtectorCore , getWeb3Provider } from ' @iexec/dataprotector' ;
219+ import { IExecWeb3telegram } from ' @iexec/web3telegram' ;
210220
211221const web3Provider = getWeb3Provider (' PRIVATE_KEY' );
222+ const dataProtectorCore = new IExecDataProtectorCore (web3Provider );
212223const web3telegram = new IExecWeb3telegram (web3Provider );
213224
214- // Step 1: Fetch contacts with bulk access
225+ // Steps 1-2: Executed by the recipient (protected data provider)
226+ // Step 1: Create Protected Data (see section 2)
227+ const protectedData = await dataProtectorCore .protectData ({
228+ data: {
229+ telegram_chatId: ' 12345678' ,
230+ },
231+ });
232+
233+ // Step 2: Grant access with bulk processing enabled (see section 3)
234+ const grantedAccess = await dataProtectorCore .grantAccess ({
235+ protectedData: protectedData .address ,
236+ authorizedApp: ' 0x456def...' ,
237+ authorizedUser: ' 0x789cba...' ,
238+ allowBulk: true ,
239+ });
240+
241+ // Steps 3-5: Executed by the sender (who wants to contact recipients)
242+ // Step 3: Fetch contacts with bulk access
215243const contacts = await web3telegram .fetchMyContacts ({ bulkOnly: true });
216244const grantedAccessArray = contacts .map ((contact ) => contact .grantedAccess );
217245
218- // Step 2 : Prepare the campaign
246+ // Step 4 : Prepare the campaign
219247const telegramCampaign = await web3telegram .prepareTelegramCampaign ({
220248 grantedAccesses: grantedAccessArray ,
221249 telegramContent: ' Hello! This is a bulk message sent to all recipients.' ,
222250 senderName: ' My Awesome App' ,
223251});
224252
225- // Step 3 : Send the bulk campaign
253+ // Step 5 : Send the bulk campaign
226254const { tasks } = await web3telegram .sendTelegramCampaign ({
227255 campaignRequest: telegramCampaign .campaignRequest ,
228256});
229257```
230258
231259:::
232260
233- ** Benefits:**
234-
235- - Lower costs: fewer transactions reduce gas fees
236- - Higher performance: multiple recipients processed in parallel
237- - Better scalability: efficiently handle hundreds or thousands of recipients
238-
239261## Payment
240262
241263Each message sent through Web3Mail or Web3Telegram requires payment in RLC
0 commit comments