Skip to content

Commit 4cebd89

Browse files
feat(sendTelegramCampaign): add allowDeposit parameter to enable automatic deposit
1 parent 8c38ea1 commit 4cebd89

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/web3telegram/sendTelegramCampaign.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
addressOrEnsSchema,
55
throwIfMissing,
66
campaignRequestSchema,
7+
booleanSchema,
78
} from '../utils/validators.js';
89
import { DataProtectorConsumer } from './internalTypes.js';
910
import {
@@ -23,6 +24,7 @@ export const sendTelegramCampaign = async ({
2324
dataProtector = throwIfMissing(),
2425
workerpoolAddressOrEns = throwIfMissing(),
2526
campaignRequest,
27+
allowDeposit = false,
2628
}: DataProtectorConsumer &
2729
SendTelegramCampaignParams): Promise<SendTelegramCampaignResponse> => {
2830
try {
@@ -36,6 +38,10 @@ export const sendTelegramCampaign = async ({
3638
.label('WorkerpoolAddressOrEns')
3739
.validateSync(workerpoolAddressOrEns);
3840

41+
const vAllowDeposit = booleanSchema()
42+
.label('allowDeposit')
43+
.validateSync(allowDeposit);
44+
3945
if (
4046
vCampaignRequest.workerpool !== NULL_ADDRESS &&
4147
vCampaignRequest.workerpool.toLowerCase() !==
@@ -47,10 +53,14 @@ export const sendTelegramCampaign = async ({
4753
}
4854

4955
// Process bulk request
56+
// TODO: Remove @ts-ignore once @iexec/dataprotector is updated to a version that includes allowDeposit in ProcessBulkRequestParams types
57+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
58+
// @ts-ignore - allowDeposit is supported at runtime but not yet in TypeScript types
5059
const processBulkRequestResponse: ProcessBulkRequestResponse<ProcessBulkRequestParams> =
5160
await dataProtector.processBulkRequest({
5261
bulkRequest: vCampaignRequest,
5362
workerpool: vWorkerpoolAddressOrEns,
63+
allowDeposit: vAllowDeposit,
5464
});
5565

5666
return processBulkRequestResponse;

src/web3telegram/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ export type SendTelegramCampaignParams = {
120120
* Workerpool address or ENS to use for processing
121121
*/
122122
workerpoolAddressOrEns?: string;
123+
/**
124+
* If true, allows automatic deposit of funds when balance is insufficient
125+
* @default false
126+
*/
127+
allowDeposit?: boolean;
123128
};
124129

125130
export type SendTelegramCampaignResponse = {

0 commit comments

Comments
 (0)