Skip to content

prepareTelegramCampaign ​

This method prepares a bulk Telegram campaign by creating a bulk request that groups multiple protected data items. The prepared campaign request can then be sent using the sendTelegramCampaign method.

INFO

This method is part of a two-step bulk campaign process:

  1. Prepare the campaign using prepareTelegramCampaign to create a bulk request
  2. Send the campaign using sendTelegramCampaign to process the bulk request

Usage ​

ts
import { 
IExecWeb3telegram
} from '@iexec/web3telegram';
const
web3Provider
=
window
.
ethereum
;
const
web3telegram
= new
IExecWeb3telegram
(
web3Provider
);
// Fetch contacts with bulk access const
contacts
= await
web3telegram
.
fetchMyContacts
({
bulkOnly
: true });
const
grantedAccessArray
=
contacts
.
map
((
contact
) =>
contact
.
grantedAccess
);
// Prepare the campaign const
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
});
ts
import { 
IExecWeb3telegram
,
getWeb3Provider
} from '@iexec/web3telegram';
const
web3Provider
=
getWeb3Provider
('PRIVATE_KEY', 'RPC_URL');
const
web3telegram
= new
IExecWeb3telegram
(
web3Provider
);
// Fetch contacts with bulk access const
contacts
= await
web3telegram
.
fetchMyContacts
({
bulkOnly
: true });
const
grantedAccessArray
=
contacts
.
map
((
contact
) =>
contact
.
grantedAccess
);
// Prepare the campaign const
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
});

Parameters ​

ts
import { type 
PrepareTelegramCampaignParams
} from '@iexec/web3telegram';

grantedAccesses Required * ​

Type: GrantedAccess[]

An array of GrantedAccess objects representing contacts who have granted you access to their protected data with bulk processing capability.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My message',
senderName
: 'My App',
});

telegramContent Required * ​

Type: string

Maximum size: 512 kb

The telegram message content that will be sent to all recipients. The content is encrypted and stored in IPFS.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
});

senderName Optional ​

Type: string | undefined

The name of the telegram message sender that will be displayed to recipients.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
});

maxProtectedDataPerTask Optional ​

Type: number | undefined

Default: 100

Limits the number of protected data items processed per task.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
maxProtectedDataPerTask
: 10,
});

workerpoolAddress Optional ​

Type: Address | undefined

Default: Default workerpool from chain configuration

The address of the workerpool that will execute the bulk campaign tasks. You can specify this during preparation or when sending the campaign.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
workerpoolAddress
: '0xa5de76...',
});

workerpoolMaxPrice Optional ​

Type: number | undefined

Default: 0

The maximum amount (in nRLC) you are willing to pay the workerpool provider for using their infrastructure to run the Web3Telegram app. You can specify this during preparation or when sending the campaign.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
workerpoolMaxPrice
: 0.1 * 1e9,
});

label Optional ​

Type: string | undefined

An optional label to identify or categorize the campaign.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
label
: 'Newsletter Campaign',
});

dataMaxPrice Optional ​

Type: number | undefined

Default: 0

The maximum amount (in nRLC) you are willing to pay for accessing the protected data.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
dataMaxPrice
: 0.1 * 1e9,
});

appMaxPrice Optional ​

Type: number | undefined

Default: 0

The maximum amount (in nRLC) you are willing to pay the Web3Telegram app provider for using the Web3Telegram application.

ts
const 
telegramCampaign
= await
web3telegram
.
prepareTelegramCampaign
({
grantedAccesses
:
grantedAccessArray
,
telegramContent
: 'My telegram message content',
senderName
: 'Awesome project team',
appMaxPrice
: 0.1 * 1e9,
});

Return Value ​

ts
import { type 
PrepareTelegramCampaignResponse
} from '@iexec/web3telegram';

campaignRequest ​

Type: BulkRequest

The prepared bulk request object that contains all the necessary information to process the bulk campaign. This object should be passed to sendTelegramCampaign to execute the campaign.

ts
const { 
tasks
} = await
web3telegram
.
sendTelegramCampaign
({
campaignRequest
:
telegramCampaign
.
campaignRequest
,
});