sendTelegramCampaign
This method sends a bulk Telegram campaign using a prepared campaign request. It processes a bulk request that has been created using the prepareTelegramCampaign method.
Prerequisites
Before using this method, make sure you have:
Recipients granted access with bulk processing: When calling
grantAccesson the Data Protector SDK, recipients must setallowBulk: truePrepared the campaign: Use
prepareTelegramCampaignto create the bulk request that will be passed to this method
Usage
import { IExecWeb3telegram } from '@iexec/web3telegram';
import { type SendTelegramCampaignResponse } from '@iexec/web3telegram';
const web3Provider = window.ethereum;
const web3telegram = new IExecWeb3telegram(web3Provider);
// Step 1: Fetch contacts and prepare the campaign
const contacts = await web3telegram.fetchMyContacts({ bulkOnly: true });
const grantedAccessArray = contacts.map((contact) => contact.grantedAccess);
const telegramCampaign = await web3telegram.prepareTelegramCampaign({
grantedAccesses: grantedAccessArray,
telegramContent: 'My telegram message content',
senderName: 'Awesome project team',
});
// Step 2: Send the campaign
const { tasks }: SendTelegramCampaignResponse =
await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});import { IExecWeb3telegram, getWeb3Provider } from '@iexec/web3telegram';
import { type SendTelegramCampaignResponse } from '@iexec/web3telegram';
const web3Provider = getWeb3Provider('PRIVATE_KEY');
const web3telegram = new IExecWeb3telegram(web3Provider);
// Step 1: Fetch contacts and prepare the campaign
const contacts = await web3telegram.fetchMyContacts({ bulkOnly: true });
const grantedAccessArray = contacts.map((contact) => contact.grantedAccess);
const telegramCampaign = await web3telegram.prepareTelegramCampaign({
grantedAccesses: grantedAccessArray,
telegramContent: 'My telegram message content',
senderName: 'Awesome project team',
});
// Step 2: Send the campaign
const result: SendTelegramCampaignResponse =
await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});Parameters
import { type SendTelegramCampaignParams } from '@iexec/web3telegram';campaignRequest Required *
Type: BulkRequest
The bulk request object returned from prepareTelegramCampaign. This contains all the necessary information to process the bulk campaign, including the grouped protected data and campaign metadata.
const { tasks } = await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
});workerpoolAddressOrEns Optional
Type: string | undefined
Default: Default workerpool from chain configuration
The workerpool address or ENS name that will execute the bulk campaign tasks.
const { tasks } = await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});Return Value
import { type SendTelegramCampaignResponse } from '@iexec/web3telegram';tasks
Type: Array<{ bulkIndex: number; taskId: string; dealId: string }>
An array of task objects created for the bulk processing campaign. Each task object contains:
bulkIndex: The index of the bulk request within the campaigntaskId: The task ID created on the iExec networkdealId: The deal ID associated with the task
Each task may process multiple protected data items depending on the bulk request configuration.
const { tasks } = await web3telegram.sendTelegramCampaign({
campaignRequest: telegramCampaign.campaignRequest,
});Related Documentation
- grantAccess Method - Grant access to protected data (recipients must set
allowBulk: trueto enable bulk processing) - fetchMyContacts Method - Fetch your contacts (use
bulkOnly: truefor bulk campaigns) - fetchUserContacts Method - Fetch contacts for a user (use
bulkOnly: truefor bulk campaigns)
