Skip to content

Commit 43ca22a

Browse files
docs(web3mail,web3telegram): add bulk processing documentation
- Add prepareEmailCampaign and sendEmailCampaign methods for Web3Mail - Add prepareTelegramCampaign and sendTelegramCampaign methods for Web3Telegram - Integrate bulk processing content into integrate-web3-messaging guide - Add bulkOnly parameter documentation to fetchMyContacts and fetchUserContacts - Add allowBulk parameter explanation to grantAccess method
1 parent 9962d7f commit 43ca22a

File tree

13 files changed

+1417
-6
lines changed

13 files changed

+1417
-6
lines changed

.vitepress/sidebar.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ export function getSidebar() {
317317
text: 'sendEmail',
318318
link: '/references/web3mail/methods/sendEmail',
319319
},
320+
{
321+
text: 'prepareEmailCampaign',
322+
link: '/references/web3mail/methods/prepareEmailCampaign',
323+
},
324+
{
325+
text: 'sendEmailCampaign',
326+
link: '/references/web3mail/methods/sendEmailCampaign',
327+
},
320328
],
321329
},
322330
{
@@ -349,6 +357,14 @@ export function getSidebar() {
349357
text: 'sendTelegram',
350358
link: '/references/web3telegram/methods/sendTelegram',
351359
},
360+
{
361+
text: 'prepareTelegramCampaign',
362+
link: '/references/web3telegram/methods/prepareTelegramCampaign',
363+
},
364+
{
365+
text: 'sendTelegramCampaign',
366+
link: '/references/web3telegram/methods/sendTelegramCampaign',
367+
},
352368
],
353369
},
354370

src/guides/use-iapp/integrate-web3-messaging.md

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ const protectedData = await dataProtectorCore.protectData({
7171

7272
Grant 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]
7577
import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector';
7678
const web3Provider = getWeb3Provider('PRIVATE_KEY');
7779
const 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]
93131
import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail';
94132

95133
const 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]
107144
import { IExecWeb3telegram, getWeb3Provider } from '@iexec/web3telegram';
108145

109146
const 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

123242
Each message sent through Web3Mail or Web3Telegram requires payment in RLC

src/references/dataProtector/methods/grantAccess.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,33 @@ const grantedAccess = await dataProtectorCore.grantAccess({
206206
});
207207
```
208208

209+
### allowBulk <OptionalBadge />
210+
211+
**Type:** `boolean`
212+
213+
**Default:** `false`
214+
215+
When set to `true`, enables bulk processing for this access grant. This allows
216+
multiple protected data items to be processed together in a single task, which
217+
is more efficient for bulk operations like sending campaigns to multiple
218+
recipients.
219+
220+
When `allowBulk: true` is set, the following parameters are automatically
221+
configured:
222+
223+
- **Price per access**: Set to `0` (no price per access)
224+
- **Number of accesses**: Set to `Number.MAX_SAFE_INTEGER` (maximum number of
225+
accesses)
226+
227+
```ts twoslash
228+
const grantedAccess = await dataProtectorCore.grantAccess({
229+
protectedData: '0x123abc...',
230+
authorizedApp: '0x456def...',
231+
authorizedUser: '0x789cba...',
232+
allowBulk: true, // [!code focus] Enable bulk processing
233+
});
234+
```
235+
209236
### onStatusUpdate <OptionalBadge />
210237

211238
**Type:** `OnStatusUpdateFn<GrantAccessStatuses>`

src/references/web3mail/methods/fetchMyContacts.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,33 @@ const contactsList = await web3mail.fetchMyContacts({
5454
});
5555
```
5656

57+
### bulkOnly <OptionalBadge />
58+
59+
**Type:** `boolean`
60+
61+
**Default:** `false`
62+
63+
When set to `true`, this parameter filters contacts to only return those who
64+
have granted access with bulk processing capability. These contacts can be used
65+
with [`prepareEmailCampaign`](/references/web3mail/methods/prepareEmailCampaign)
66+
and [`sendEmailCampaign`](/references/web3mail/methods/sendEmailCampaign) for
67+
bulk campaigns.
68+
69+
::: warning
70+
71+
To enable bulk processing, recipients must grant access with `allowBulk: true`
72+
when calling [`grantAccess`](/references/dataProtector/methods/grantAccess) on
73+
the Data Protector SDK.
74+
75+
:::
76+
77+
```ts twoslash
78+
// Fetch contacts with bulk access
79+
const bulkContacts = await web3mail.fetchMyContacts({
80+
bulkOnly: true, // [!code focus]
81+
});
82+
```
83+
5784
## Return Value
5885

5986
The result object contains a list of `contact` objects. Each `contact`
@@ -67,5 +94,5 @@ import { type Contact } from '@iexec/web3mail';
6794
[`Contact[]`](/references/dataProtector/types#contact)
6895

6996
<script setup>
70-
import OptionalBadge from '@/components/OptionalBadge.vue'
97+
import OptionalBadge from '@/components/OptionalBadge.vue';
7198
</script>

src/references/web3mail/methods/fetchUserContacts.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ const contactsList = await web3mail.fetchUserContacts({
7474
});
7575
```
7676

77+
### bulkOnly <OptionalBadge />
78+
79+
**Type:** `boolean`
80+
81+
**Default:** `false`
82+
83+
When set to `true`, this parameter filters contacts to only return those who
84+
have granted access with bulk processing capability. These contacts can be used
85+
with [`prepareEmailCampaign`](/references/web3mail/methods/prepareEmailCampaign)
86+
and [`sendEmailCampaign`](/references/web3mail/methods/sendEmailCampaign) for
87+
bulk campaigns.
88+
89+
::: warning
90+
91+
To enable bulk processing, recipients must grant access with `allowBulk: true`
92+
when calling [`grantAccess`](/references/dataProtector/methods/grantAccess) on
93+
the Data Protector SDK.
94+
95+
:::
96+
97+
```ts twoslash
98+
// Fetch contacts with bulk access for a specific user
99+
const bulkContacts = await web3mail.fetchUserContacts({
100+
bulkOnly: true, // [!code focus]
101+
});
102+
```
103+
77104
## Return Value
78105

79106
The result object contains a list of `contact` objects. Each `contact`
@@ -87,5 +114,6 @@ import { type Contact } from '@iexec/web3mail';
87114
[`Contract[]`](/references/dataProtector/types#contact)
88115

89116
<script setup>
90-
import RequiredBadge from '@/components/RequiredBadge.vue'
117+
import RequiredBadge from '@/components/RequiredBadge.vue';
118+
import OptionalBadge from '@/components/OptionalBadge.vue';
91119
</script>

0 commit comments

Comments
 (0)