Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Borodin committed Jun 24, 2024
1 parent 09fcad5 commit 781c4f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
TEST_GROUP_ID: ${{ secrets.TEST_GROUP_ID }}
TEST_GROUP_MEMBER_ID: ${{ secrets.TEST_GROUP_MEMBER_ID }}
run: npm test
continue-on-error: true

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,21 @@ export class TelegramBot extends EventEmitter {
testEnvironment: boolean;
baseURL: string;
autoRetry: boolean;
autoRetryLimit: number;

constructor(options: {
botToken: string;
testEnvironment?: boolean;
baseURL?: string;
autoRetry?: boolean;
autoRetryLimit?: number;
}) {
super();
this.testEnvironment = options.testEnvironment || false;
this.botToken = options.botToken;
this.baseURL = options.baseURL || 'https://api.telegram.org';
this.autoRetry = options.autoRetry ?? true;
this.autoRetryLimit = options.autoRetryLimit || 0;
this.polling = new Polling(this, []);
}

Expand Down Expand Up @@ -186,7 +189,11 @@ export class TelegramBot extends EventEmitter {
return response.result as T;
} else {
const error = response as ErrorResponse;
if (this.autoRetry && error.parameters?.retry_after) {
if (
this.autoRetry &&
error.parameters?.retry_after &&
error.parameters?.retry_after < this.autoRetryLimit
) {
await wait(error.parameters.retry_after * 1000);
return await this.callApi(method, options);
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TEST_GROUP_MEMBER_ID = parseInt(
const bot = new TelegramBot({
botToken: TOKEN,
autoRetry: true,
autoRetryLimit: 30,
});

describe('TelegramBot', () => {
Expand Down

0 comments on commit 781c4f9

Please sign in to comment.