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:
- Prepare the campaign using
prepareTelegramCampaignto create a bulk request - Send the campaign using
sendTelegramCampaignto process the bulk request
Usage
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',
});import { IExecWeb3telegram, getWeb3Provider } from '@iexec/web3telegram';
const web3Provider = getWeb3Provider('PRIVATE_KEY');
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
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.
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.
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.
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.
const telegramCampaign = await web3telegram.prepareTelegramCampaign({
grantedAccesses: grantedAccessArray,
telegramContent: 'My telegram message content',
senderName: 'Awesome project team',
maxProtectedDataPerTask: 10,
});workerpoolAddressOrEns Optional
Type: AddressOrENS | undefined
Default: Default workerpool from chain configuration
The workerpool address or ENS name that will execute the bulk campaign tasks. You can specify this during preparation or when sending the campaign.
const telegramCampaign = await web3telegram.prepareTelegramCampaign({
grantedAccesses: grantedAccessArray,
telegramContent: 'My telegram message content',
senderName: 'Awesome project team',
workerpoolAddressOrEns: '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.
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.
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.
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.
const telegramCampaign = await web3telegram.prepareTelegramCampaign({
grantedAccesses: grantedAccessArray,
telegramContent: 'My telegram message content',
senderName: 'Awesome project team',
appMaxPrice: 0.1 * 1e9,
});Return Value
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.
const { tasks } = await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
});Related Documentation
- sendTelegramCampaign Method - Send a prepared bulk campaign
