Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/web3telegram/prepareTelegramCampaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
label,
appMaxPrice = MAX_DESIRED_APP_ORDER_PRICE,
workerpoolMaxPrice = MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
grantedAccess,
grantedAccesses,
maxProtectedDataPerTask,
}: IExecConsumer &
DappAddressConsumer &
Expand Down Expand Up @@ -122,13 +122,13 @@
args: vLabel,
inputFiles: [],
secrets,
bulkAccesses: grantedAccess,
bulkAccesses: grantedAccesses,
maxProtectedDataPerTask: vMaxProtectedDataPerTask,
});
return { campaignRequest };
} catch (error) {
// Protocol error detected, re-throwing as-is
if ((error as any)?.isProtocolError === true) {

Check warning on line 131 in src/web3telegram/prepareTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / check-code

Unexpected any. Specify a different type

Check warning on line 131 in src/web3telegram/prepareTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / npm-publish-dry-run / publish-npm / build

Unexpected any. Specify a different type
throw error;
}
// Handle protocol errors - this will throw if it's an ApiCallError
Expand Down
10 changes: 6 additions & 4 deletions src/web3telegram/sendTelegramCampaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
} from '../utils/validators.js';
import { DataProtectorConsumer } from './internalTypes.js';
import {
BulkRequest,
ProcessBulkRequestParams,
ProcessBulkRequestResponse,
} from '@iexec/dataprotector';
import { ValidationError } from 'yup';
import {
CampaignRequest,
SendTelegramCampaignParams,
SendTelegramCampaignResponse,
} from './types.js';
Expand All @@ -29,7 +29,7 @@
const vCampaignRequest = campaignRequestSchema()
.required()
.label('campaignRequest')
.validateSync(campaignRequest) as BulkRequest;
.validateSync(campaignRequest) as CampaignRequest;

const vWorkerpoolAddressOrEns = addressOrEnsSchema()
.required()
Expand All @@ -41,19 +41,21 @@
vCampaignRequest.workerpool.toLowerCase() !==
vWorkerpoolAddressOrEns.toLowerCase()
) {
throw new ValidationError('Workerpool mismatch');
throw new ValidationError(
"workerpoolAddressOrEns doesn't match campaignRequest workerpool"
);
}

// Process bulk request
const processBulkRequestResponse: ProcessBulkRequestResponse<ProcessBulkRequestParams> =
await dataProtector.processBulkRequest({
bulkRequest: vCampaignRequest as BulkRequest,
bulkRequest: vCampaignRequest,
workerpool: vWorkerpoolAddressOrEns,
});

return processBulkRequestResponse;
} catch (error) {
if ((error as any)?.isProtocolError === true) {

Check warning on line 58 in src/web3telegram/sendTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / check-code

Unexpected any. Specify a different type

Check warning on line 58 in src/web3telegram/sendTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / npm-publish-dry-run / publish-npm / build

Unexpected any. Specify a different type
throw error;
}
handleIfProtocolError(error);
Expand All @@ -61,7 +63,7 @@
error instanceof Error &&
error.message === 'Failed to process protected data';
if (isProcessProtectedDataError) {
const cause = (error as any)?.cause;

Check warning on line 66 in src/web3telegram/sendTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / check-code

Unexpected any. Specify a different type

Check warning on line 66 in src/web3telegram/sendTelegramCampaign.ts

View workflow job for this annotation

GitHub Actions / npm-publish-dry-run / publish-npm / build

Unexpected any. Specify a different type
const unwrappedCause = cause instanceof Error ? cause : error;
throw new WorkflowError({
message: 'Failed to sendTelegramCampaign',
Expand Down
37 changes: 32 additions & 5 deletions src/web3telegram/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ export type Address = string;

export type TimeStamp = string;

/**
* request to send email in bulk
*
* use `prepareEmailCampaign()` to create a `CampaignRequest`
*
* then use `sendEmailCampaign()` to send the campaign
*/
export type CampaignRequest = BulkRequest;

/**
* authorization signed by the data owner granting access to this contact
*
* `GrantedAccess` are obtained by fetching contacts (e.g. `fetchMyContacts()` or `fetchUserContacts()`)
*
* `GrantedAccess` can be consumed for email campaigns (e.g. `prepareEmailCampaign()` then `sendEmailCampaign()`)
*/
export type GrantedAccess = {
dataset: string;
datasetprice: string;
Expand Down Expand Up @@ -70,11 +86,11 @@ export type SendTelegramResponse = {

export type PrepareTelegramCampaignParams = {
/**
* Granted access to process in bulk.
* List of `GrantedAccess` to contacts to send telegrams to in bulk.
*
* use `fetchMyContacts({ bulkOnly: true })` to get granted accesses.
* if not provided, the single message will be processed.
*/
grantedAccess: GrantedAccess[];
grantedAccesses: GrantedAccess[];
maxProtectedDataPerTask?: number;
senderName?: string;
telegramContent: string;
Expand All @@ -86,11 +102,22 @@ export type PrepareTelegramCampaignParams = {
};

export type PrepareTelegramCampaignResponse = {
campaignRequest: BulkRequest;
/**
* The prepared campaign request
*
* Use this in `sendTelegramCampaign()` to start or continue sending the campaign
*/
campaignRequest: CampaignRequest;
};

export type SendTelegramCampaignParams = {
campaignRequest: BulkRequest;
/**
* The prepared campaign request from prepareTelegramCampaign
*/
campaignRequest: CampaignRequest;
/**
* Workerpool address or ENS to use for processing
*/
workerpoolAddressOrEns?: string;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/prepareTelegramCampaign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('web3telegram.prepareTelegramCampaign()', () => {
telegramContent: 'Bulk test message',
senderName: 'Bulk test sender',
// protectedData is optional when grantedAccess is provided
grantedAccess: bulkOrders,
grantedAccesses: bulkOrders,
maxProtectedDataPerTask: 3,
workerpoolMaxPrice: prodWorkerpoolPublicPrice,
});
Expand Down
Loading
Loading