11import { AbstractProvider , AbstractSigner , Eip1193Provider } from 'ethers' ;
22import { IExec } from 'iexec' ;
3+ import { IExecDataProtectorCore } from '@iexec/dataprotector' ;
34import { GraphQLClient } from 'graphql-request' ;
45import { fetchUserContacts } from './fetchUserContacts.js' ;
56import { fetchMyContacts } from './fetchMyContacts.js' ;
67import { sendTelegram } from './sendTelegram.js' ;
8+ import { sendTelegramCampaign } from './sendTelegramCampaign.js' ;
79import {
810 Contact ,
911 FetchUserContactsParams ,
1012 SendTelegramParams ,
1113 AddressOrENS ,
1214 Web3TelegramConfigOptions ,
13- SendTelegramResponse ,
1415 Web3SignerProvider ,
1516 FetchMyContactsParams ,
17+ SendTelegramResponse ,
18+ PrepareTelegramCampaignResponse ,
19+ PrepareTelegramCampaignParams ,
20+ SendTelegramCampaignParams ,
21+ SendTelegramCampaignResponse ,
1622} from './types.js' ;
1723import { getChainDefaultConfig } from '../config/config.js' ;
1824import { isValidProvider } from '../utils/validators.js' ;
1925import { getChainIdFromProvider } from '../utils/getChainId.js' ;
2026import { resolveDappAddressFromCompass } from '../utils/resolveDappAddressFromCompass.js' ;
27+ import { prepareTelegramCampaign } from './prepareTelegramCampaign.js' ;
2128
2229type EthersCompatibleProvider =
2330 | AbstractProvider
@@ -34,6 +41,7 @@ interface Web3telegramResolvedConfig {
3441 ipfsGateway : string ;
3542 defaultWorkerpool : string ;
3643 iexec : IExec ;
44+ dataProtector : IExecDataProtectorCore ;
3745}
3846
3947export class IExecWeb3telegram {
@@ -51,6 +59,8 @@ export class IExecWeb3telegram {
5159
5260 private iexec ! : IExec ;
5361
62+ private dataProtector ! : IExecDataProtectorCore ;
63+
5464 private initPromise : Promise < void > | null = null ;
5565
5666 private ethProvider : EthersCompatibleProvider ;
@@ -75,6 +85,7 @@ export class IExecWeb3telegram {
7585 this . ipfsGateway = config . ipfsGateway ;
7686 this . defaultWorkerpool = config . defaultWorkerpool ;
7787 this . iexec = config . iexec ;
88+ this . dataProtector = config . dataProtector ;
7889 } ) ;
7990 }
8091 return this . initPromise ;
@@ -121,6 +132,34 @@ export class IExecWeb3telegram {
121132 } ) ;
122133 }
123134
135+ async sendTelegramCampaign (
136+ args : SendTelegramCampaignParams
137+ ) : Promise < SendTelegramCampaignResponse > {
138+ await this . init ( ) ;
139+ await isValidProvider ( this . iexec ) ;
140+ return sendTelegramCampaign ( {
141+ ...args ,
142+ workerpoolAddressOrEns :
143+ args . workerpoolAddressOrEns || this . defaultWorkerpool ,
144+ dataProtector : this . dataProtector ,
145+ } ) ;
146+ }
147+
148+ async prepareTelegramCampaign (
149+ args : PrepareTelegramCampaignParams
150+ ) : Promise < PrepareTelegramCampaignResponse > {
151+ await this . init ( ) ;
152+
153+ return prepareTelegramCampaign ( {
154+ ...args ,
155+ iexec : this . iexec ,
156+ dataProtector : this . dataProtector ,
157+ ipfsNode : this . ipfsNode ,
158+ ipfsGateway : this . ipfsGateway ,
159+ dappAddressOrENS : this . dappAddressOrENS ,
160+ } ) ;
161+ }
162+
124163 private async resolveConfig ( ) : Promise < Web3telegramResolvedConfig > {
125164 const chainId = await getChainIdFromProvider ( this . ethProvider ) ;
126165 const chainDefaultConfig = getChainDefaultConfig ( chainId , {
@@ -185,6 +224,17 @@ export class IExecWeb3telegram {
185224 throw new Error ( `Failed to create GraphQLClient: ${ error . message } ` ) ;
186225 }
187226
227+ const dataProtector = new IExecDataProtectorCore ( this . ethProvider , {
228+ iexecOptions : {
229+ ipfsGatewayURL : ipfsGateway ,
230+ ...this . options ?. iexecOptions ,
231+ allowExperimentalNetworks : this . options . allowExperimentalNetworks ,
232+ } ,
233+ ipfsGateway,
234+ ipfsNode,
235+ subgraphUrl,
236+ } ) ;
237+
188238 return {
189239 dappAddressOrENS,
190240 dappWhitelistAddress : dappWhitelistAddress . toLowerCase ( ) ,
@@ -193,6 +243,7 @@ export class IExecWeb3telegram {
193243 ipfsNode,
194244 ipfsGateway,
195245 iexec,
246+ dataProtector,
196247 } ;
197248 }
198249}
0 commit comments