├── scripts └── bin │ ├── .gitkeep │ ├── pre-commit.sh │ └── gitAddMod.sh ├── .prettierignore ├── .vscode └── settings.json ├── commitlint.config.js ├── src ├── telegram.constants.ts ├── index.ts ├── interfaces │ ├── index.ts │ ├── telegram-module-options.interface.ts │ └── telegramTypes.interface.ts ├── telegram.provider.ts ├── telegram.module.spec.ts ├── telegram.module.ts ├── telegram.service.ts └── telegram.service.spec.ts ├── .prettierrc ├── nest-cli.json ├── tsconfig.build.json ├── .snyk ├── .huskyrc ├── .travis.yml ├── .npmignore ├── jest.config.js ├── .github └── dependabot.yml ├── tsconfig.json ├── LICENSE ├── .gitignore ├── package.json ├── tslint.json └── README.md /scripts/bin/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Add files here to ignore them from prettier formatting 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "callout" 4 | ] 5 | } -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ['@commitlint/config-conventional'] }; 2 | -------------------------------------------------------------------------------- /src/telegram.constants.ts: -------------------------------------------------------------------------------- 1 | export const TELEGRAM_MODULE_OPTIONS = 'TELEGRAM_MODULE_OPTIONS'; 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "arrowParens": "always", 4 | "trailingComma": "all" 5 | } 6 | -------------------------------------------------------------------------------- /nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ts", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src" 5 | } 6 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interfaces'; 2 | export * from './telegram.module'; 3 | export * from './telegram.service'; 4 | -------------------------------------------------------------------------------- /src/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './telegram-module-options.interface'; 2 | export * from './telegramTypes.interface'; 3 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. 2 | version: v1.13.5 3 | ignore: {} 4 | patch: {} 5 | -------------------------------------------------------------------------------- /scripts/bin/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | npm run lint 4 | npm run format:check || npm run format 5 | bash scripts/bin/gitAddMod.sh 6 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "bash scripts/bin/pre-commit.sh", 4 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 10.15.3 4 | cache: 5 | directories: 6 | - node_modules 7 | install: npm ci 8 | script: npm run test -- --runInBand --coverageReporters=text-lcov | coveralls 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | .vscode/ 3 | .gitignore/ 4 | .huskyrc 5 | .prettier* 6 | .snyk 7 | .travis.yml 8 | commitlint* 9 | jest.* 10 | nest-cli* 11 | nodemon* 12 | tsconfig.* 13 | tslint* 14 | coverage/ 15 | reference/ 16 | scripts/ 17 | test/ 18 | package-lock.json -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | moduleFileExtensions: ['js', 'json', 'ts'], 3 | rootDir: 'src', 4 | testRegex: '.spec.ts$', 5 | transform: { 6 | '^.+\\.(t|j)s$': 'ts-jest', 7 | }, 8 | coverageDirectory: '../coverage', 9 | collectCoverage: true, 10 | testEnvironment: 'node', 11 | }; 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "13:00" 8 | open-pull-requests-limit: 10 9 | target-branch: dependabot 10 | ignore: 11 | - dependency-name: "@nestjs/testing" 12 | versions: 13 | - ">= 7.a, < 8" 14 | -------------------------------------------------------------------------------- /src/telegram.provider.ts: -------------------------------------------------------------------------------- 1 | import { Provider } from '@nestjs/common'; 2 | import { TelegramModuleOptions } from './interfaces/telegram-module-options.interface'; 3 | import { TELEGRAM_MODULE_OPTIONS } from './telegram.constants'; 4 | 5 | export function createTelegramProvider( 6 | options: TelegramModuleOptions, 7 | ): Provider[] { 8 | return [ 9 | { 10 | provide: TELEGRAM_MODULE_OPTIONS, 11 | useValue: options || {}, 12 | }, 13 | ]; 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "declaration": true, 6 | "removeComments": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "target": "es6", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "sourceRoot": "./src" 15 | }, 16 | "exclude": ["node_modules"] 17 | } 18 | -------------------------------------------------------------------------------- /scripts/bin/gitAddMod.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | files=$(git diff --name-status) 3 | index=0 4 | newArray=() 5 | addString="" 6 | for i in ${files[*]} 7 | do 8 | newArray[$index]=$i 9 | index=$((index+1)) 10 | done 11 | for ((i=0; i<${#newArray[*]}; i++)) 12 | do 13 | if [[ ${newArray[$i]} == *"A" ]] || [[ ${newArray[$i]} == *"M" ]] 14 | then 15 | i=$((i+1)) 16 | addString=$addString' '${newArray[$i]} 17 | fi 18 | if [[ ${newArray[$i]} == *"D" ]] || [[ ${newArray[$i]} == *"R" ]] 19 | then 20 | i=$((i+1)) 21 | fi 22 | done; 23 | if [[ -n $addString ]] 24 | then 25 | git add$addString 26 | fi -------------------------------------------------------------------------------- /src/interfaces/telegram-module-options.interface.ts: -------------------------------------------------------------------------------- 1 | import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; 2 | 3 | export interface TelegramModuleOptions { 4 | botKey: string; 5 | } 6 | 7 | export interface TelegramOptionsFactory { 8 | createTelegramOptions(): 9 | | Promise 10 | | TelegramModuleOptions; 11 | } 12 | 13 | export interface TelegramModuleAsyncOptions 14 | extends Pick { 15 | useExisting?: Type; 16 | useClass?: Type; 17 | useFactory?: ( 18 | ...args: any[] 19 | ) => Promise | TelegramModuleOptions; 20 | inject?: any[]; 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jay McDoniel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # OS 14 | .DS_Store 15 | 16 | # Tests 17 | /coverage 18 | /.nyc_output 19 | 20 | # IDEs and editors 21 | /.idea 22 | .project 23 | .classpath 24 | .c9/ 25 | *.launch 26 | .settings/ 27 | *.sublime-workspace 28 | 29 | # IDE - VSCode 30 | .vscode/* 31 | !.vscode/settings.json 32 | !.vscode/tasks.json 33 | !.vscode/launch.json 34 | !.vscode/extensions.json 35 | 36 | # Logs 37 | logs 38 | *.log 39 | npm-debug.log* 40 | yarn-debug.log* 41 | yarn-error.log* 42 | 43 | # Runtime data 44 | pids 45 | *.pid 46 | *.seed 47 | *.pid.lock 48 | 49 | # Directory for instrumented libs generated by jscoverage/JSCover 50 | lib-cov 51 | 52 | # Coverage directory used by tools like istanbul 53 | coverage 54 | 55 | # nyc test coverage 56 | .nyc_output 57 | 58 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 59 | .grunt 60 | 61 | # Bower dependency directory (https://bower.io/) 62 | bower_components 63 | 64 | # node-waf configuration 65 | .lock-wscript 66 | 67 | # Compiled binary addons (https://nodejs.org/api/addons.html) 68 | build/Release 69 | 70 | # Dependency directories 71 | node_modules/ 72 | jspm_packages/ 73 | 74 | # TypeScript v1 declaration files 75 | typings/ 76 | 77 | # Optional npm cache directory 78 | .npm 79 | 80 | # Optional eslint cache 81 | .eslintcache 82 | 83 | # Optional REPL history 84 | .node_repl_history 85 | 86 | # Output of 'npm pack' 87 | *.tgz 88 | 89 | # Yarn Integrity file 90 | .yarn-integrity 91 | 92 | # dotenv environment variables file 93 | .env 94 | reference/ 95 | 96 | # next.js build output 97 | .next -------------------------------------------------------------------------------- /src/telegram.module.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test } from '@nestjs/testing'; 2 | import { TelegramModule } from './telegram.module'; 3 | 4 | describe('telegramModule', () => { 5 | describe('forRoot', () => { 6 | it('should be defined', async () => { 7 | const module = await Test.createTestingModule({ 8 | imports: [TelegramModule.forRoot({ botKey: 'someBotToken' })], 9 | }); 10 | expect(module).toBeDefined(); 11 | }); 12 | }); 13 | describe('forRootAsync', () => { 14 | it('should be defined (factory)', async () => { 15 | const module = await Test.createTestingModule({ 16 | imports: [ 17 | TelegramModule.forRootAsync({ 18 | useFactory: () => { 19 | return { botKey: 'someKey' }; 20 | }, 21 | }), 22 | ], 23 | }); 24 | expect(module).toBeDefined(); 25 | }); 26 | it('should be defined (factory)(inject)', async () => { 27 | const module = await Test.createTestingModule({ 28 | imports: [ 29 | TelegramModule.forRootAsync({ 30 | useFactory: (config: { [key: string]: any }) => { 31 | return config.botKey; 32 | }, 33 | inject: [ 34 | { 35 | provide: 'Config', 36 | useValue: { botKey: 'someKey' }, 37 | }, 38 | ], 39 | }), 40 | ], 41 | }); 42 | expect(module).toBeDefined(); 43 | }); 44 | it('should be defined (useClass)', async () => { 45 | const module = await Test.createTestingModule({ 46 | imports: [ 47 | TelegramModule.forRootAsync({ 48 | useClass: {} as any, 49 | }), 50 | ], 51 | }); 52 | expect(module).toBeDefined(); 53 | }); 54 | it('should be defined (factory)', async () => { 55 | const module = await Test.createTestingModule({ 56 | imports: [ 57 | TelegramModule.forRootAsync({ 58 | useExisting: {} as any, 59 | }), 60 | ], 61 | }); 62 | expect(module).toBeDefined(); 63 | }); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /src/telegram.module.ts: -------------------------------------------------------------------------------- 1 | import { DynamicModule, Module, Provider } from '@nestjs/common'; 2 | import { HttpModule } from '@nestjs/axios'; 3 | import { 4 | TelegramModuleAsyncOptions, 5 | TelegramModuleOptions, 6 | TelegramOptionsFactory, 7 | } from './interfaces/telegram-module-options.interface'; 8 | import { TELEGRAM_MODULE_OPTIONS } from './telegram.constants'; 9 | import { createTelegramProvider } from './telegram.provider'; 10 | import { TelegramService } from './telegram.service'; 11 | 12 | @Module({ 13 | imports: [HttpModule], 14 | providers: [TelegramService], 15 | exports: [TelegramService], 16 | }) 17 | export class TelegramModule { 18 | static forRoot(options: TelegramModuleOptions): DynamicModule { 19 | return { 20 | module: TelegramModule, 21 | providers: createTelegramProvider(options), 22 | }; 23 | } 24 | 25 | static forRootAsync(options: TelegramModuleAsyncOptions): DynamicModule { 26 | return { 27 | module: TelegramModule, 28 | imports: options.imports || [], 29 | providers: this.createAsyncProvider(options), 30 | }; 31 | } 32 | 33 | private static createAsyncProvider( 34 | options: TelegramModuleAsyncOptions, 35 | ): Provider[] { 36 | if (options.useExisting || options.useFactory) { 37 | return [this.createAsyncOptionsProvider(options)]; 38 | } 39 | return [ 40 | this.createAsyncOptionsProvider(options), 41 | { 42 | provide: options.useClass, 43 | useClass: options.useClass, 44 | }, 45 | ]; 46 | } 47 | 48 | private static createAsyncOptionsProvider( 49 | options: TelegramModuleAsyncOptions, 50 | ): Provider { 51 | if (options.useFactory) { 52 | return { 53 | provide: TELEGRAM_MODULE_OPTIONS, 54 | useFactory: options.useFactory, 55 | inject: options.inject || [], 56 | }; 57 | } 58 | return { 59 | provide: TELEGRAM_MODULE_OPTIONS, 60 | useFactory: async (optionsFactory: TelegramOptionsFactory) => 61 | await optionsFactory.createTelegramOptions(), 62 | inject: [options.useExisting || options.useClass], 63 | }; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nestjs-telegram", 3 | "version": "1.2.0", 4 | "description": "A NestJS Module for Telegram Bots", 5 | "author": { 6 | "email": "me@jaymcdoniel.dev", 7 | "name": "Jay McDoniel" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/jmcdo29/nestjs-telegram" 12 | }, 13 | "types": "./dist/index.d.ts", 14 | "main": "./dist/index.js", 15 | "license": "MIT", 16 | "keywords": [ 17 | "nest", 18 | "nestjs", 19 | "telegram", 20 | "bot" 21 | ], 22 | "scripts": { 23 | "build": "rimraf dist && tsc -p tsconfig.build.json", 24 | "format": "prettier --write \"src/**/*.ts\"", 25 | "format:check": "prettier --check \"src/**/*.ts\"", 26 | "start": "node dist/main.js", 27 | "start:dev": "tsc-watch --onSuccess \"node -r tsconfig-paths/register dist/main.js\" --onFailure \"echo 'There was a problem compiling'\"", 28 | "start:debug": "tsc-watch --onSuccess \"node --inspect-brk -r tsconfig-paths/register dist/main.js\" --onFailure \"echo 'There was a problem compiling'\"", 29 | "lint": "tslint -p tsconfig.json -c tslint.json", 30 | "test": "jest", 31 | "test:watch": "jest --watch", 32 | "test:cov": "jest --coverage", 33 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 34 | "test:e2e": "jest --config ./test/jest-e2e.json" 35 | }, 36 | "dependencies": { 37 | "@nestjs/axios": "^1.0.1", 38 | "@nestjs/common": "^9.2.1", 39 | "@nestjs/core": "^9.2.1", 40 | "reflect-metadata": "^0.1.13", 41 | "rxjs": "^7.8.0" 42 | }, 43 | "devDependencies": { 44 | "@commitlint/cli": "^17.4.2", 45 | "@commitlint/config-conventional": "^17.4.2", 46 | "@nestjs/testing": "^9.2.1", 47 | "@types/express": "^4.17.16", 48 | "@types/jest": "^29.4.0", 49 | "@types/node": "^18.11.18", 50 | "@types/supertest": "^2.0.12", 51 | "coveralls": "^3.1.1", 52 | "husky": "^8.0.3", 53 | "jest": "^29.4.1", 54 | "npm-check": "^6.0.1", 55 | "prettier": "^2.8.3", 56 | "rimraf": "^4.1.2", 57 | "supertest": "^6.3.3", 58 | "ts-jest": "29.0.5", 59 | "ts-node": "^10.9.1", 60 | "tsc-watch": "^6.0.0", 61 | "tsconfig-paths": "4.1.2", 62 | "tslint": "^6.1.3", 63 | "tslint-config-prettier": "^1.18.0", 64 | "typescript": "^4.9.4" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [], 3 | "extends": ["tslint:recommended", "tslint-config-prettier"], 4 | "rules": { 5 | "arrow-return-shorthand": true, 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [true, "check-space"], 9 | "curly": true, 10 | "eofline": true, 11 | "forin": true, 12 | "import-spacing": true, 13 | "indent": [true, "spaces"], 14 | "interface-name": false, 15 | "interface-over-type-literal": true, 16 | "label-position": true, 17 | "max-line-length": [true, 140], 18 | "member-access": false, 19 | "member-ordering": [ 20 | true, 21 | { 22 | "order": [ 23 | "static-field", 24 | "instance-field", 25 | "static-method", 26 | "instance-method" 27 | ] 28 | } 29 | ], 30 | "no-arg": true, 31 | "no-bitwise": true, 32 | "no-console": [true, "log", "debug", "info", "time", "timeEnd", "trace"], 33 | "no-construct": true, 34 | "no-debugger": true, 35 | "no-duplicate-super": true, 36 | "no-empty": false, 37 | "no-empty-interface": false, 38 | "no-eval": true, 39 | "no-inferrable-types": [true, "ignore-params"], 40 | "no-misused-new": true, 41 | "no-non-null-assertion": true, 42 | "no-shadowed-variable": true, 43 | "no-string-literal": false, 44 | "no-string-throw": true, 45 | "no-switch-case-fall-through": true, 46 | "no-trailing-whitespace": true, 47 | "no-unnecessary-initializer": true, 48 | "no-unused-expression": true, 49 | "no-var-keyword": true, 50 | "object-literal-sort-keys": false, 51 | "one-line": [ 52 | true, 53 | "check-open-brace", 54 | "check-catch", 55 | "check-else", 56 | "check-whitespace" 57 | ], 58 | "prefer-const": true, 59 | "quotemark": [true, "single", "warn"], 60 | "radix": false, 61 | "semicolon": [true, "always"], 62 | "trailing-comma": true, 63 | "triple-equals": [true, "allow-null-check"], 64 | "typedef-whitespace": [ 65 | true, 66 | { 67 | "call-signature": "nospace", 68 | "index-signature": "nospace", 69 | "parameter": "nospace", 70 | "property-declaration": "nospace", 71 | "variable-declaration": "nospace" 72 | } 73 | ], 74 | "unified-signatures": true, 75 | "variable-name": false, 76 | "whitespace": [ 77 | true, 78 | "check-branch", 79 | "check-decl", 80 | "check-operator", 81 | "check-separator", 82 | "check-type" 83 | ] 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logoplus Telegram Logo 3 |

4 | 5 |

A NestJS service wrapper for Telegram bots! 6 |

7 |

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

16 |

17 |

18 | 19 | ## Description 20 | 21 | [Telegram](https://telegram.org) API wrapper for the Telegram Bots API made to work with the [Nest](https://github.com/nestjs/nest) framework. 22 | 23 | ## Installation 24 | 25 | ```bash 26 | $ npm install nestjs-telegram 27 | ``` 28 | 29 | ## Using the Module 30 | 31 | ```typescript 32 | // Inside of your module imports 33 | @Module({ 34 | imports: [TelegramModule.forRoot({ 35 | botKey: 'YourBotApiToken' 36 | })] 37 | }) 38 | 39 | // Or async 40 | @Module({ 41 | imports: [ 42 | TelegramModule.forRootAsync({ 43 | useFactory: async (configService: ConfigService) => ({ 44 | botKey: configService.get('Telegram_API_Key') 45 | }), 46 | inject: [ConfigService] 47 | }) 48 | ], 49 | }) 50 | ``` 51 | 52 | In your service class you can inject the service like so and then use it in any function as you would any other service 53 | ```typescript 54 | @Injectable() 55 | export class MyService { 56 | 57 | constructor(private readonly telegram: TelegramService) {} 58 | 59 | testBot(): Observable { 60 | return this.telegram.getMe(); 61 | } 62 | } 63 | ``` 64 | 65 | Currently, the service only returns `Observables` as the `HttpModule` does. If you want to use `Promises` just call `.toPromise()` on the function. 66 | 67 | ## Support 68 | 69 | If any bugs are found in the API wrapper, please open an issue on GitHub, or a Pull Request if you want to fix it yourself! Please be as explicit as possible and provide a minimum reproducing repository if at all possible, as it helps track down what went wrong. 70 | 71 | ## Documentation 72 | 73 | All documentation for this wrapper comes from the [Telegram Bot API documentation](https://core.telegram.org/bots/api), if there are any typos, please let me know or open a PR to fix it. 74 | 75 | ## Todo 76 | 77 | * Implement Telegram Passport methods 78 | * Implement Telegram Inline mode options 79 | 80 | ## Stay in touch 81 | 82 | - Author - [Jay McDoniel](https://github.com/jmcdo29) 83 | 84 | ## License 85 | 86 | Nestjs-telegram is [MIT licensed](LICENSE). 87 | -------------------------------------------------------------------------------- /src/telegram.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, OnModuleInit } from '@nestjs/common'; 2 | import { HttpService } from '@nestjs/axios'; 3 | import { AxiosRequestConfig } from 'axios'; 4 | import { Observable } from 'rxjs'; 5 | import { catchError, map } from 'rxjs/operators'; 6 | import { TelegramModuleOptions } from './interfaces'; 7 | import * as Telegram from './interfaces/telegramTypes.interface'; 8 | import { TELEGRAM_MODULE_OPTIONS } from './telegram.constants'; 9 | 10 | @Injectable() 11 | export class TelegramService implements OnModuleInit { 12 | private url: string; 13 | 14 | constructor( 15 | @Inject(TELEGRAM_MODULE_OPTIONS) 16 | private readonly options: TelegramModuleOptions, 17 | private readonly http: HttpService, 18 | ) {} 19 | 20 | onModuleInit() { 21 | this.url = `https://api.telegram.org/bot${this.options.botKey}/`; 22 | } 23 | 24 | private doCall( 25 | url: string, 26 | data?: any, 27 | axiosOptions?: AxiosRequestConfig, 28 | ): Observable { 29 | return this.http 30 | .post>(this.url + url, data, axiosOptions) 31 | .pipe( 32 | map((res: any) => { 33 | if (!res.data.ok) { 34 | throw new Telegram.TelegramException( 35 | res.data.description, 36 | res.data.error_code.toString(), 37 | ); 38 | } 39 | return res.data.result; 40 | }), 41 | catchError((error: Error) => { 42 | throw new Telegram.TelegramException(error.message); 43 | }), 44 | ); 45 | } 46 | 47 | /** 48 | * Use this method to receive incoming updates using long polling. 49 | */ 50 | getUpdates(data: Telegram.GetUpdatesParams): Observable { 51 | return this.doCall(this.getUpdates.name, data); 52 | } 53 | 54 | /** 55 | * A simple method for testing your bot's auth token. Requires no parameters. 56 | * Returns basic information about the bot in form of a User object. 57 | */ 58 | getMe(): Observable { 59 | return this.doCall(this.getMe.name, {}); 60 | } 61 | 62 | /** 63 | * Use this method to send text messages. On success, the sent Message is returned. 64 | * 65 | * ### Formatting options 66 | * The Bot API supports basic formatting for messages. You can use bold and italic text, as well as inline links and pre-formatted 67 | * code in your bots' messages. 68 | * clients will render them accordingly. You can use either markdown-style or HTML-style formatting. 69 | * 70 | * Note that clients will display an alert to the user before opening an inline link 71 | * (‘Open this link?’ together with the full URL). 72 | * 73 | * Links tg://user?id= can be used to mention a user by their id without using a username. Please note: 74 | * 75 | * These links will work only if they are used inside an inline link. For example, they will not work, 76 | * when used in an inline keyboard button or in a message text. 77 | * These mentions are only guaranteed to work if the user has contacted the bot in the past, 78 | * has sent a callback query to the bot via inline button or is a member in the group where he was mentioned. 79 | * 80 | * 81 | * 82 | * Markdown style 83 | * To use this mode, pass Markdown in the parse_mode field when using sendMessage. Use the following syntax in your message: 84 | * 85 | * \*bold text\* 86 | * 87 | * \_italic text\_ 88 | * 89 | * \[inline URL\]\(http://www.example.com/\) 90 | * 91 | * \[inline mention of a user\]\(tg://user?id=123456789\) 92 | * 93 | * \`inline fixed-width code\` 94 | * 95 | * \`\`\`block_language 96 | * pre-formatted fixed-width code block 97 | * \`\`\` 98 | * 99 | * 100 | * 101 | * HTML style 102 | * To use this mode, pass HTML in the parse_mode field when using sendMessage. The following tags are currently supported: 103 | * 104 | * bold, bold 105 | * 106 | * italic, italic 107 | * 108 | * inline URL 109 | * 110 | * inline mention of a user 111 | * 112 | * inline fixed-width code 113 | * 114 | *
pre-formatted fixed-width code block
115 | * 116 | * Please note: 117 | * Only the tags mentioned above are currently supported. 118 | * Tags must not be nested. 119 | * All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the 120 | * corresponding HTML entities (< with <, > with > and & with &). 121 | * All numerical HTML entities are supported. 122 | * The API currently supports only the following named HTML entities: <, >, & and ". 123 | */ 124 | sendMessage( 125 | data: Telegram.TelegramSendMessageParams, 126 | ): Observable { 127 | return this.doCall(this.sendMessage.name, data); 128 | } 129 | 130 | /** 131 | * Use this method to forward messages of any kind. On success, the sent Message is returned. 132 | */ 133 | forwardMessage( 134 | data: Telegram.TelegramForwardMessageParams, 135 | ): Observable { 136 | return this.doCall( 137 | this.forwardMessage.name, 138 | data, 139 | ); 140 | } 141 | 142 | /** 143 | * Use this method to send photos. On success, the sent Message is returned. 144 | */ 145 | sendPhoto( 146 | data: Telegram.TelegramSendPhotoParams, 147 | ): Observable { 148 | return this.doCall(this.sendPhoto.name, data, { 149 | headers: { 150 | 'Content-Type': 151 | typeof data.photo === 'object' 152 | ? 'multipart/form-data' 153 | : 'application/json', 154 | }, 155 | }); 156 | } 157 | 158 | /** 159 | * Use this method to send audio files, if you want Telegram clients to display them in the music player. 160 | * Your audio must be in the .mp3 format. On success, the sent Message is returned. 161 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. 162 | * 163 | * For sending voice messages, use the sendVoice method instead. 164 | */ 165 | sendAudio( 166 | data: Telegram.TelegramSendAudioParams, 167 | ): Observable { 168 | return this.doCall(this.sendAudio.name, data, { 169 | headers: { 170 | 'Content-Type': 171 | typeof data.audio === 'object' || typeof data.thumb === 'object' 172 | ? 'multipart/form-data' 173 | : 'application/json', 174 | }, 175 | }); 176 | } 177 | 178 | /** 179 | * Use this method to send general files. On success, the sent Message is returned. 180 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. 181 | */ 182 | sendDocument( 183 | data: Telegram.TelegramSendDocumentParams, 184 | ): Observable { 185 | return this.doCall(this.sendDocument.name, data, { 186 | headers: { 187 | 'Content-Type': 188 | typeof data.document === 'object' || typeof data.thumb === 'object' 189 | ? 'multipart/form-data' 190 | : 'application/json', 191 | }, 192 | }); 193 | } 194 | 195 | /** 196 | * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). 197 | * On success, the sent Message is returned. 198 | * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. 199 | */ 200 | sendVideo( 201 | data: Telegram.TelegramSendVideoParams, 202 | ): Observable { 203 | return this.doCall(this.sendVideo.name, data, { 204 | headers: { 205 | 'Content-Type': 206 | typeof data.video === 'object' || typeof data.thumb === 'object' 207 | ? 'multipart/form-data' 208 | : 'application/json', 209 | }, 210 | }); 211 | } 212 | 213 | /** 214 | * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). 215 | * On success, the sent Message is returned. 216 | * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. 217 | */ 218 | sendAnimation( 219 | data: Telegram.TelegramSendAnimationParams, 220 | ): Observable { 221 | return this.doCall( 222 | this.sendAnimation.name, 223 | data, 224 | { 225 | headers: { 226 | 'Content-Type': 227 | typeof data.animation === 'object' || typeof data.thumb === 'object' 228 | ? 'multipart/form-data' 229 | : 'application/json', 230 | }, 231 | }, 232 | ); 233 | } 234 | 235 | /** 236 | * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. 237 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). 238 | * On success, the sent Message is returned. 239 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. 240 | */ 241 | sendVoice( 242 | data: Telegram.TelegramSendVoiceParams, 243 | ): Observable { 244 | return this.doCall(this.sendVoice.name, data, { 245 | headers: { 246 | 'Content-Type': 247 | typeof data.voice === 'object' || typeof data.thumb === 'object' 248 | ? 'multipart/form-data' 249 | : 'application/json', 250 | }, 251 | }); 252 | } 253 | 254 | /** 255 | * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. 256 | * On success, the sent Message is returned. 257 | */ 258 | sendVideoNote( 259 | data: Telegram.TelegramSendVideoNoteParams, 260 | ): Observable { 261 | return this.doCall( 262 | this.sendVideoNote.name, 263 | data, 264 | { 265 | headers: { 266 | 'Content-Type': 267 | typeof data.video_note === 'object' || 268 | typeof data.thumb === 'object' 269 | ? 'multipart/form-data' 270 | : 'application/json', 271 | }, 272 | }, 273 | ); 274 | } 275 | 276 | /** 277 | * Use this method to send a group of photos or videos as an album. On success, an array of the sent Messages is returned. 278 | */ 279 | sendMediaGroup( 280 | data: Telegram.TelegramSendMediaGroupParams, 281 | ): Observable { 282 | return this.doCall( 283 | this.sendMediaGroup.name, 284 | data, 285 | { 286 | headers: { 287 | 'Content-Type': 'multipart/form-data', 288 | }, 289 | }, 290 | ); 291 | } 292 | 293 | /** 294 | * Use this method to send point on the map. On success, the sent Message is returned. 295 | */ 296 | sendLocation( 297 | data: Telegram.TelegramSendLocationParams, 298 | ): Observable { 299 | return this.doCall(this.sendLocation.name, data); 300 | } 301 | 302 | /** 303 | * Use this method to edit live location messages. 304 | * A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. 305 | * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. 306 | */ 307 | editMessageLiveLocation( 308 | data: Telegram.TelegramEditMessageLiveLocationParams, 309 | ): Observable { 310 | return this.doCall( 311 | this.editMessageLiveLocation.name, 312 | data, 313 | ); 314 | } 315 | 316 | /** 317 | * Use this method to stop updating a live location message before live_period expires. 318 | * On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned. 319 | */ 320 | stopMessageLiveLocation( 321 | data: Telegram.TelegramStopMessageLiveLocationParams, 322 | ): Observable { 323 | return this.doCall( 324 | this.stopMessageLiveLocation.name, 325 | data, 326 | ); 327 | } 328 | 329 | /** 330 | * Use this method to send information about a venue. On success, the sent Message is returned. 331 | */ 332 | sendVenue( 333 | data: Telegram.TelegramSendVenueParams, 334 | ): Observable { 335 | return this.doCall(this.sendVenue.name, data); 336 | } 337 | 338 | /** 339 | * Use this method to send phone contacts. On success, the sent Message is returned. 340 | */ 341 | sendContact( 342 | data: Telegram.TelegramSendContactParams, 343 | ): Observable { 344 | return this.doCall(this.sendContact.name, data); 345 | } 346 | 347 | /** 348 | * Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned. 349 | */ 350 | sendPoll( 351 | data: Telegram.TelegramSendPollParams, 352 | ): Observable { 353 | return this.doCall(this.sendPoll.name, data); 354 | } 355 | 356 | /** 357 | * Use this method when you need to tell the user that something is happening on the bot's side. 358 | * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). 359 | * Returns True on success. 360 | * 361 | * > Example: The [ImageBot](https://t.me/imagebotc) needs some time to process a request and upload the image. 362 | * Instead of sending a text message along the lines of “Retrieving image, please wait…”, 363 | * the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot. 364 | * 365 | * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. 366 | */ 367 | sendChatAction( 368 | data: Telegram.TelegramSendChatActionParams, 369 | ): Observable { 370 | return this.doCall(this.sendChatAction.name, data); 371 | } 372 | 373 | /** 374 | * Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. 375 | */ 376 | getUserProfilePhotos( 377 | data: Telegram.TelegramGetUserProfilePhotosParams, 378 | ): Observable { 379 | return this.doCall( 380 | this.getUserProfilePhotos.name, 381 | data, 382 | ); 383 | } 384 | 385 | /** 386 | * Use this method to get basic info about a file and prepare it for downloading. 387 | * For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. 388 | * The file can then be downloaded via the link 389 | * `https://api.telegram.org/file/bot/`, where `` is taken from the response. 390 | * It is guaranteed that the link will be valid for at least 1 hour. 391 | * When the link expires, a new one can be requested by calling getFile again. 392 | * 393 | * **Note**: This function may not preserve the original file name and MIME type. 394 | * You should save the file's MIME type and name (if available) when the File object is received. 395 | */ 396 | getFile( 397 | data: Telegram.TelegramGetFileParams, 398 | ): Observable { 399 | return this.doCall(this.getFile.name, data); 400 | } 401 | 402 | /** 403 | * Use this method to kick a user from a group, a supergroup or a channel. 404 | * In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., 405 | * unless unbanned first. The bot must be an administrator in the chat for this to 406 | * work and must have the appropriate admin rights. Returns True on success. 407 | * 408 | * > **Note**: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ 409 | * setting is off in the target group. Otherwise members may only be removed by the group's creator or by the member that added them. 410 | */ 411 | kickChatMember( 412 | data: Telegram.TelegramKickChatMemberParams, 413 | ): Observable { 414 | return this.doCall(this.kickChatMember.name, data); 415 | } 416 | 417 | /** 418 | * Use this method to unban a previously kicked user in a supergroup or channel. 419 | * The user will not return to the group or channel automatically, but will be able to join via link, etc. 420 | * The bot must be an administrator for this to work. Returns True on success. 421 | */ 422 | unbanChatMember( 423 | data: Telegram.TelegramUnbanChatMemberParams, 424 | ): Observable { 425 | return this.doCall(this.unbanChatMember.name, data); 426 | } 427 | 428 | /** 429 | * Use this method to restrict a user in a supergroup. 430 | * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. 431 | * Pass True for all boolean parameters to lift restrictions from a user. Returns True on success. 432 | */ 433 | restrictChatMember( 434 | data: Telegram.TelegramRestrictChatMemberParams, 435 | ): Observable { 436 | return this.doCall(this.restrictChatMember.name, data); 437 | } 438 | 439 | /** 440 | * Use this method to promote or demote a user in a supergroup or a channel. 441 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 442 | * Pass False for all boolean parameters to demote a user. Returns True on success. 443 | */ 444 | promoteChatMember( 445 | data: Telegram.TelegramPromoteChatMemberParams, 446 | ): Observable { 447 | return this.doCall(this.promoteChatMember.name, data); 448 | } 449 | 450 | /** 451 | * Use this method to generate a new invite link for a chat; any previously generated link is revoked. 452 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 453 | * Returns the new invite link as String on success. 454 | * 455 | * > **Note:**Each administrator in a chat generates their own invite links. 456 | * Bots can't use invite links generated by other administrators. 457 | * If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink – 458 | * after this the link will become available to the bot via the getChat method. 459 | * If your bot needs to generate a new invite link replacing its previous one, use exportChatInviteLink again. 460 | */ 461 | exportChatInviteLink( 462 | data: Telegram.TelegramExportChatInviteLinkParams, 463 | ): Observable { 464 | return this.doCall(this.exportChatInviteLink.name, data); 465 | } 466 | 467 | /** 468 | * Use this method to set a new profile photo for the chat. 469 | * Photos can't be changed for private chats. 470 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 471 | * Returns True on success. 472 | * 473 | * > **Note:** In regular groups (non-supergroups), this method will only work 474 | * if the ‘All Members Are Admins’ setting is off in the target group. 475 | */ 476 | setChatPhoto(data: Telegram.TelegramSetChatPhotoParams): Observable { 477 | return this.doCall(this.setChatPhoto.name, data, { 478 | headers: { 479 | 'Content-Type': 'multipart/form-data', 480 | }, 481 | }); 482 | } 483 | 484 | /** 485 | * Use this method to delete a chat photo. Photos can't be changed for private chats. 486 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. 487 | * 488 | * > **Note:** In regular groups (non-supergroups), this method will only work if the 489 | * ‘All Members Are Admins’ setting is off in the target group. 490 | */ 491 | deleteChatPhoto( 492 | data: Telegram.TelegramDeleteChatPhotoParams, 493 | ): Observable { 494 | return this.doCall(this.deleteChatPhoto.name, data); 495 | } 496 | 497 | /** 498 | * Use this method to change the title of a chat. 499 | * Titles can't be changed for private chats. The bot must be an 500 | * administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. 501 | * 502 | * > **Note:** In regular groups (non-supergroups), this method will only work if the 503 | * ‘All Members Are Admins’ setting is off in the target group. 504 | */ 505 | setChatTitle(data: Telegram.TelegramSetChatTitleParams): Observable { 506 | return this.doCall(this.setChatTitle.name, data); 507 | } 508 | 509 | /** 510 | * Use this method to change the description of a supergroup or a channel. 511 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 512 | * Returns True on success. 513 | */ 514 | setChatDescription( 515 | data: Telegram.TelegramSetChatDescriptionParams, 516 | ): Observable { 517 | return this.doCall(this.setChatDescription.name, data); 518 | } 519 | 520 | /** 521 | * Use this method to pin a message in a group, a supergroup, or a channel. 522 | * The bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ 523 | * admin right in the supergroup or ‘can_edit_messages’ admin right in the channel. Returns True on success. 524 | */ 525 | pinChatMessage( 526 | data: Telegram.TelegramPinChatMessageParams, 527 | ): Observable { 528 | return this.doCall(this.pinChatMessage.name, data); 529 | } 530 | 531 | /** 532 | * Use this method to unpin a message in a group, a supergroup, or a channel. 533 | * The bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ 534 | * admin right in the supergroup or ‘can_edit_messages’ admin right in the channel. Returns True on success. 535 | */ 536 | unpinChatMessage( 537 | data: Telegram.TelegramUnpinChatMessageParams, 538 | ): Observable { 539 | return this.doCall(this.unpinChatMessage.name, data); 540 | } 541 | 542 | /** 543 | * Use this method for your bot to leave a group, supergroup or channel. Returns True on success. 544 | */ 545 | leaveChat(data: Telegram.TelegramLeaveChatParams): Observable { 546 | return this.doCall(this.leaveChat.name, data); 547 | } 548 | 549 | /** 550 | * Use this method to get up to date information about the chat 551 | * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). 552 | * Returns a Chat object on success. 553 | */ 554 | getChat( 555 | data: Telegram.TelegramGetChatParams, 556 | ): Observable { 557 | return this.doCall(this.getChat.name, data); 558 | } 559 | 560 | /** 561 | * Use this method to get a list of administrators in a chat. 562 | * On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. 563 | * If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. 564 | */ 565 | getChatAdministrators( 566 | data: Telegram.TelegramGetChatAdministratorsParams, 567 | ): Observable { 568 | return this.doCall( 569 | this.getChatAdministrators.name, 570 | data, 571 | ); 572 | } 573 | 574 | /** 575 | * Use this method to get the number of members in a chat. Returns Int on success. 576 | */ 577 | getChatMembersCount( 578 | data: Telegram.TelegramGetChatMembersCountParams, 579 | ): Observable { 580 | return this.doCall(this.getChatMembersCount.name, data); 581 | } 582 | 583 | /** 584 | * Use this method to get information about a member of a chat. Returns a ChatMember object on success. 585 | */ 586 | getChatMember( 587 | data: Telegram.TelegramGetChatMemberParams, 588 | ): Observable { 589 | return this.doCall( 590 | this.getChatMember.name, 591 | data, 592 | ); 593 | } 594 | 595 | /** 596 | * Use this method to set a new group sticker set for a supergroup. 597 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 598 | * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. 599 | * Returns True on success. 600 | */ 601 | setChatStickerSet( 602 | data: Telegram.TelegramSetChatStickerSetParams, 603 | ): Observable { 604 | return this.doCall(this.setChatStickerSet.name, data); 605 | } 606 | 607 | /** 608 | * Use this method to delete a group sticker set from a supergroup. 609 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. 610 | * Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. 611 | * Returns True on success. 612 | */ 613 | deleteChatStickerSet( 614 | data: Telegram.TelegramChatDeleteStickerSetParams, 615 | ): Observable { 616 | return this.doCall(this.deleteChatStickerSet.name, data); 617 | } 618 | 619 | /** 620 | * Use this method to send answers to callback queries sent from inline keyboards. 621 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. 622 | * On success, True is returned. 623 | * 624 | * > Alternatively, the user can be redirected to the specified Game URL. 625 | * For this option to work, you must first create a game for your bot via [@Botfather](https://t.me/botfather) and accept the terms. 626 | * Otherwise, you may use links like `t.me/your_bot?start=XXXX` that open your bot with a parameter. 627 | */ 628 | answerCallbackQuery( 629 | data: Telegram.TelegramAnswerCallbackQueryParams, 630 | ): Observable { 631 | return this.doCall(this.answerCallbackQuery.name, data); 632 | } 633 | 634 | /** 635 | * Use this method to edit text and game messages. 636 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. 637 | */ 638 | editMessageText( 639 | data: Telegram.TelegramEditMessageTextParams, 640 | ): Observable { 641 | return this.doCall( 642 | this.editMessageText.name, 643 | data, 644 | ); 645 | } 646 | 647 | /** 648 | * Use this method to edit captions of messages. 649 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. 650 | */ 651 | editMessageCaption( 652 | data: Telegram.TelegramEditMessageCaptionParams, 653 | ): Observable { 654 | return this.doCall( 655 | this.editMessageCaption.name, 656 | data, 657 | ); 658 | } 659 | 660 | /** 661 | * Use this method to edit animation, audio, document, photo, or video messages. 662 | * If a message is a part of a message album, then it can be edited only to a 663 | * photo or a video. Otherwise, message type can be changed arbitrarily. 664 | * When inline message is edited, new file can't be uploaded. 665 | * Use previously uploaded file via its file_id or specify a URL. 666 | * On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. 667 | */ 668 | editMessageMedia( 669 | data: Telegram.TelegramEditMessageMediaParams, 670 | ): Observable { 671 | return this.doCall( 672 | this.editMessageMedia.name, 673 | data, 674 | { 675 | headers: { 676 | 'Content-Type': 'multipart/form-data', 677 | }, 678 | }, 679 | ); 680 | } 681 | 682 | /** 683 | * Use this method to edit only the reply markup of messages. 684 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. 685 | */ 686 | editMessageReplyMarkup( 687 | data: Telegram.TelegramEditMessageReplyMarkupParams, 688 | ): Observable { 689 | return this.doCall( 690 | this.editMessageReplyMarkup.name, 691 | data, 692 | ); 693 | } 694 | 695 | /** 696 | * Use this method to stop a poll which was sent by the bot. 697 | * On success, the stopped Poll with the final results is returned. 698 | */ 699 | stopPoll( 700 | data: Telegram.TelegramStopPollParams, 701 | ): Observable { 702 | return this.doCall( 703 | this.editMessageReplyMarkup.name, 704 | data, 705 | ); 706 | } 707 | 708 | /** 709 | * Use this method to delete a message, including service messages, with the following limitations: 710 | * 711 | * - A message can only be deleted if it was sent less than 48 hours ago. 712 | * - Bots can delete outgoing messages in private chats, groups, and supergroups. 713 | * - Bots can delete incoming messages in private chats. 714 | * - Bots granted can_post_messages permissions can delete outgoing messages in channels. 715 | * - If the bot is an administrator of a group, it can delete any message there. 716 | * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. 717 | * 718 | * Returns True on success. 719 | */ 720 | deleteMessage(data: Telegram.TelegramDeleteMessageParams): Observable { 721 | return this.doCall(this.deleteMessage.name, data); 722 | } 723 | 724 | /** 725 | * Use this method to send .webp stickers. On success, the sent Message is returned. 726 | */ 727 | sendSticker( 728 | data: Telegram.TelegramSendStickerParams, 729 | ): Observable { 730 | return this.doCall(this.sendSticker.name, data, { 731 | headers: { 732 | 'Content-Type': 733 | typeof data.sticker === 'object' 734 | ? 'multipart/form-data' 735 | : 'application/json', 736 | }, 737 | }); 738 | } 739 | 740 | /** 741 | * Use this method to get a sticker set. On success, a StickerSet object is returned. 742 | */ 743 | getStickerSet( 744 | data: Telegram.TelegramGetStickerSetParams, 745 | ): Observable { 746 | return this.doCall( 747 | this.getStickerSet.name, 748 | data, 749 | ); 750 | } 751 | 752 | /** 753 | * Use this method to upload a .png file with a sticker for later use in 754 | * createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. 755 | */ 756 | uploadStickerFile( 757 | data: Telegram.TelegramUploadStickerFileParams, 758 | ): Observable { 759 | return this.doCall( 760 | this.uploadStickerFile.name, 761 | data, 762 | { 763 | headers: { 764 | 'Content-Type': 'multipart/form-data', 765 | }, 766 | }, 767 | ); 768 | } 769 | 770 | /** 771 | * Use this method to create new sticker set owned by a user. 772 | * The bot will be able to edit the created sticker set. Returns True on success. 773 | */ 774 | createNewStickerSet( 775 | data: Telegram.TelegramCreateNewStickerSetParams, 776 | ): Observable { 777 | return this.doCall(this.createNewStickerSet.name, data, { 778 | headers: { 779 | 'Content-Type': 780 | typeof data.png_sticker === 'object' 781 | ? 'multipart/form-data' 782 | : 'application/json', 783 | }, 784 | }); 785 | } 786 | 787 | /** 788 | * Use this method to add a new sticker to a set created by the bot. Returns True on success. 789 | */ 790 | addStickerToSet( 791 | data: Telegram.TelegramAddStickerToSetParams, 792 | ): Observable { 793 | return this.doCall(this.addStickerToSet.name, data, { 794 | headers: { 795 | 'Content-Type': 796 | typeof data.png_sticker === 'object' 797 | ? 'multipart/form-data' 798 | : 'application/json', 799 | }, 800 | }); 801 | } 802 | 803 | /** 804 | * Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success. 805 | */ 806 | setStickerPositionInSet( 807 | data: Telegram.TelegramSetStickerPositionInSetParams, 808 | ): Observable { 809 | return this.doCall(this.setStickerPositionInSet.name, data); 810 | } 811 | 812 | /** 813 | * Use this method to delete a sticker from a set created by the bot. Returns True on success. 814 | */ 815 | deleteStickerFromSet( 816 | data: Telegram.TelegramDeleteStickerFromSetParams, 817 | ): Observable { 818 | return this.doCall(this.deleteStickerFromSet.name, data); 819 | } 820 | 821 | /** 822 | * Use this method to send invoices. On success, the sent Message is returned. 823 | */ 824 | sendInvoice( 825 | data: Telegram.TelegramSendInvoiceParams, 826 | ): Observable { 827 | return this.doCall(this.sendInvoice.name, data); 828 | } 829 | 830 | /** 831 | * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, 832 | * the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. 833 | * On success, True is returned. 834 | */ 835 | answerShippingQuery( 836 | data: Telegram.TelegramAnswerShippingQueryParams, 837 | ): Observable { 838 | return this.doCall(this.answerShippingQuery.name, data); 839 | } 840 | 841 | /** 842 | * Once the user has confirmed their payment and shipping details, 843 | * the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. 844 | * Use this method to respond to such pre-checkout queries. 845 | * On success, True is returned. 846 | * **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. 847 | */ 848 | answerPreCheckoutQuery( 849 | data: Telegram.TelegramAnswerPreCheckoutQueryParams, 850 | ): Observable { 851 | return this.doCall(this.answerPreCheckoutQuery.name, data); 852 | } 853 | 854 | /** 855 | * Use this method to send a game. On success, the sent Message is returned. 856 | */ 857 | sendGame( 858 | data: Telegram.TelegramSendGameParams, 859 | ): Observable { 860 | return this.doCall(this.sendGame.name, data); 861 | } 862 | 863 | /** 864 | * Use this method to set the score of the specified user in a game. 865 | * On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. 866 | * Returns an error, if the new score is not greater than the user's current score in the chat and force is False. 867 | */ 868 | setGameScore( 869 | data: Telegram.TelegramSetGameScoreParams, 870 | ): Observable { 871 | return this.doCall( 872 | this.setGameScore.name, 873 | data, 874 | ); 875 | } 876 | 877 | /** 878 | * Use this method to get data for high score tables. 879 | * Will return the score of the specified user and several of his neighbors in a game. 880 | * On success, returns an Array of GameHighScore objects. 881 | * 882 | * > This method will currently return scores for the target user, plus two of his closest neighbors on each side. 883 | * Will also return the top three users if the user and his neighbors are not among them. 884 | * Please note that this behavior is subject to change. 885 | */ 886 | getGameHighScore( 887 | data: Telegram.TelegramGetGameHighScoreParams, 888 | ): Observable { 889 | return this.doCall( 890 | this.getGameHighScore.name, 891 | data, 892 | ); 893 | } 894 | } 895 | -------------------------------------------------------------------------------- /src/telegram.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { of } from 'rxjs'; 3 | import { 4 | TelegramChat, 5 | TelegramChatMember, 6 | TelegramException, 7 | TelegramFile, 8 | TelegramGameHighScore, 9 | TelegramMessage, 10 | TelegramPoll, 11 | TelegramResponse, 12 | TelegramSendMessageParams, 13 | TelegramStickerSet, 14 | TelegramUser, 15 | TelegramUserProfilePhotos, 16 | } from './interfaces/telegramTypes.interface'; 17 | import { TelegramService } from './telegram.service'; 18 | 19 | const postMock = jest.fn(); 20 | 21 | const multiPartHeader = { headers: { 'Content-Type': 'multipart/form-data' } }; 22 | 23 | const telegramObserver = ( 24 | done: () => void, 25 | expectedData: T, 26 | calledTimes: number, 27 | calledWith?: any, 28 | ) => ({ 29 | next(nextValue: T) { 30 | expect(nextValue).toEqual(expectedData); 31 | expect(postMock).toHaveBeenCalledTimes(calledTimes); 32 | if (calledWith) { 33 | expect(postMock.mock.calls[0][2]).toEqual(calledWith); 34 | } 35 | }, 36 | error(error: Error) { 37 | throw error; 38 | }, 39 | complete() { 40 | done(); 41 | }, 42 | }); 43 | 44 | const axiosRes = (response: TelegramResponse) => ({ 45 | data: response, 46 | }); 47 | 48 | const telegramRes = (response: T) => ({ 49 | ok: true, 50 | result: response, 51 | }); 52 | 53 | const httpMock = { 54 | post: postMock, 55 | }; 56 | 57 | const sendMessageParams: TelegramSendMessageParams = { 58 | chat_id: 8754, 59 | text: 'This is a test', 60 | }; 61 | 62 | const chat: TelegramChat = { 63 | id: 8754, 64 | type: 'group', 65 | }; 66 | 67 | const message: TelegramMessage = { 68 | message_id: 4587, 69 | chat, 70 | date: 45778965, 71 | }; 72 | 73 | const user: TelegramUser = { 74 | id: 45872, 75 | is_bot: true, 76 | first_name: 'Test_bot', 77 | }; 78 | 79 | describe('TelegramService', () => { 80 | let module: TestingModule; 81 | let service: TelegramService; 82 | 83 | beforeEach(async () => { 84 | module = await Test.createTestingModule({ 85 | providers: [ 86 | { 87 | provide: TelegramService, 88 | useFactory: () => { 89 | return new TelegramService( 90 | { botKey: 'someBotKey' }, 91 | httpMock as any, 92 | ); 93 | }, 94 | }, 95 | ], 96 | }).compile(); 97 | 98 | service = module.get(TelegramService); 99 | }); 100 | 101 | afterEach(() => { 102 | jest.clearAllMocks(); 103 | }); 104 | 105 | describe('module initialization', () => { 106 | beforeEach(() => { 107 | module.init(); 108 | }); 109 | 110 | it('should still be defined', () => { 111 | expect(service).toBeDefined(); 112 | }); 113 | }); 114 | 115 | it('should be defined', () => { 116 | expect(service).toBeDefined(); 117 | }); 118 | describe('doPoll handle error', () => { 119 | it('should resolve if there is an error', (done) => { 120 | postMock.mockReturnValueOnce( 121 | of( 122 | axiosRes({ ok: false, error_code: 400, description: 'Bad request' }), 123 | ), 124 | ); 125 | service.getMe().subscribe({ 126 | next(nextValue) { 127 | throw new Error('Test should have gone to fail observer'); 128 | }, 129 | error(error: Error) { 130 | expect(error.toString()).toEqual( 131 | new TelegramException('Bad request', '400').toString(), 132 | ); 133 | done(); 134 | }, 135 | complete() { 136 | done(); 137 | }, 138 | }); 139 | }); 140 | }); 141 | describe('getMe', () => { 142 | it('should return the bot user', (done) => { 143 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(user)))); 144 | service.getMe().subscribe(telegramObserver(done, user, 1)); 145 | }); 146 | }); 147 | describe('sendMessage', () => { 148 | it('should get the response for sendMessage', (done) => { 149 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 150 | service 151 | .sendMessage(sendMessageParams) 152 | .subscribe(telegramObserver(done, message, 1)); 153 | }); 154 | }); 155 | describe('forwardMessage', () => { 156 | it('should get the response for forwardMessage', (done) => { 157 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 158 | service 159 | .forwardMessage({ 160 | from_chat_id: 7854, 161 | chat_id: 5698, 162 | message_id: 5, 163 | }) 164 | .subscribe(telegramObserver(done, message, 1)); 165 | }); 166 | }); 167 | describe('sendMedia', () => { 168 | describe('sendPhoto', () => { 169 | it('should get the response for sendPhoto (multipart)', (done) => { 170 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 171 | service 172 | .sendPhoto({ 173 | chat_id: 8754, 174 | photo: Buffer.alloc('string'.length, 'string'), 175 | }) 176 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 177 | }); 178 | it('should get the response for sendPhoto (string)', (done) => { 179 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 180 | service 181 | .sendPhoto({ 182 | chat_id: 8754, 183 | photo: 'string url of photo', 184 | }) 185 | .subscribe(telegramObserver(done, message, 1)); 186 | }); 187 | }); 188 | describe('sendAudio', () => { 189 | it('should get the response for sendAudio (multipart)', (done) => { 190 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 191 | service 192 | .sendAudio({ 193 | chat_id: 8754, 194 | audio: Buffer.alloc(10), 195 | }) 196 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 197 | }); 198 | it('should get the response for sendAudio (string)', (done) => { 199 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 200 | service 201 | .sendAudio({ 202 | chat_id: 8754, 203 | audio: Buffer.alloc(10).toString(), 204 | }) 205 | .subscribe(telegramObserver(done, message, 1)); 206 | }); 207 | }); 208 | describe('sendDocument', () => { 209 | it('should get the response for sendDocument (multipart)', (done) => { 210 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 211 | service 212 | .sendDocument({ 213 | chat_id: 8754, 214 | document: Buffer.alloc(10), 215 | }) 216 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 217 | }); 218 | it('should get the response for sendDocument (string)', (done) => { 219 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 220 | service 221 | .sendDocument({ 222 | chat_id: 8754, 223 | document: Buffer.alloc(10).toString(), 224 | }) 225 | .subscribe(telegramObserver(done, message, 1)); 226 | }); 227 | }); 228 | describe('sendVideo', () => { 229 | it('should get the response for sendVideo (multipart)', (done) => { 230 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 231 | service 232 | .sendVideo({ 233 | chat_id: 8754, 234 | video: Buffer.alloc(10), 235 | }) 236 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 237 | }); 238 | it('should get the response for sendVideo (string)', (done) => { 239 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 240 | service 241 | .sendVideo({ 242 | chat_id: 8754, 243 | video: Buffer.alloc(10).toString(), 244 | }) 245 | .subscribe(telegramObserver(done, message, 1)); 246 | }); 247 | }); 248 | describe('sendAnimation', () => { 249 | it('should get the response for sendAnimation (multipart)', (done) => { 250 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 251 | service 252 | .sendAnimation({ 253 | chat_id: 8754, 254 | animation: Buffer.alloc(10), 255 | }) 256 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 257 | }); 258 | it('should get the response for sendAnimation (string)', (done) => { 259 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 260 | service 261 | .sendAnimation({ 262 | chat_id: 8754, 263 | animation: Buffer.alloc(10).toString(), 264 | }) 265 | .subscribe(telegramObserver(done, message, 1)); 266 | }); 267 | }); 268 | describe('sendVoice', () => { 269 | it('should get the response for sendVoice (multipart)', (done) => { 270 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 271 | service 272 | .sendVoice({ 273 | chat_id: 8754, 274 | voice: Buffer.alloc(10), 275 | video_note: Buffer.alloc(10), 276 | }) 277 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 278 | }); 279 | it('should get the response for sendVoice (multipart)', (done) => { 280 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 281 | service 282 | .sendVoice({ 283 | chat_id: 8754, 284 | voice: Buffer.alloc(10).toString(), 285 | video_note: Buffer.alloc(10).toString(), 286 | }) 287 | .subscribe(telegramObserver(done, message, 1)); 288 | }); 289 | }); 290 | describe('sendVideoNote', () => { 291 | it('should get the response for sendVideoNote (multipart)', (done) => { 292 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 293 | service 294 | .sendVideoNote({ 295 | chat_id: 8754, 296 | video_note: Buffer.alloc(10), 297 | }) 298 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 299 | }); 300 | it('should get the response for sendVideoNote (string)', (done) => { 301 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 302 | service 303 | .sendVideoNote({ 304 | chat_id: 8754, 305 | video_note: Buffer.alloc(10).toString(), 306 | }) 307 | .subscribe(telegramObserver(done, message, 1)); 308 | }); 309 | }); 310 | describe('sendMediaGroup', () => { 311 | it('should get the response for sendMediaGroup (multipart)', (done) => { 312 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes([message])))); 313 | service 314 | .sendMediaGroup({ 315 | chat_id: 8754, 316 | media: [ 317 | { 318 | type: 'photo', 319 | media: Buffer.alloc(10), 320 | }, 321 | ], 322 | }) 323 | .subscribe(telegramObserver(done, [message], 1, multiPartHeader)); 324 | }); 325 | }); 326 | }); 327 | describe('sendLocation', () => { 328 | it('should get the response for sendLocation', (done) => { 329 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 330 | service 331 | .sendLocation({ 332 | chat_id: 8754, 333 | latitude: 87878, 334 | longitude: 9875, 335 | }) 336 | .subscribe(telegramObserver(done, message, 1)); 337 | }); 338 | }); 339 | describe('editMessageLiveLocation', () => { 340 | it('should get the response for editMessageLiveLocation(message)', (done) => { 341 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 342 | service 343 | .editMessageLiveLocation({ 344 | chat_id: 7854, 345 | latitude: 54545, 346 | longitude: 54545, 347 | }) 348 | .subscribe(telegramObserver(done, message, 1)); 349 | }); 350 | it('should get the response for editMessageLiveLocation(true)', (done) => { 351 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 352 | service 353 | .editMessageLiveLocation({ 354 | chat_id: 7854, 355 | latitude: 54545, 356 | longitude: 54545, 357 | }) 358 | .subscribe(telegramObserver(done, true, 1)); 359 | }); 360 | }); 361 | describe('stopMessageLiveLocation', () => { 362 | it('should get the response for stopMessageLiveLocation(message)', (done) => { 363 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 364 | service 365 | .stopMessageLiveLocation({ 366 | chat_id: 7854, 367 | }) 368 | .subscribe(telegramObserver(done, message, 1)); 369 | }); 370 | it('should get the response for stopMessageLiveLocation(true)', (done) => { 371 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 372 | service 373 | .stopMessageLiveLocation({ 374 | chat_id: 7854, 375 | }) 376 | .subscribe(telegramObserver(done, true, 1)); 377 | }); 378 | }); 379 | describe('sendVenue', () => { 380 | it('should get the response for sendVenue', (done) => { 381 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 382 | service 383 | .sendVenue({ 384 | chat_id: 8754, 385 | latitude: 545454, 386 | longitude: 54587, 387 | title: 'some venue', 388 | address: 'the address', 389 | }) 390 | .subscribe(telegramObserver(done, message, 1)); 391 | }); 392 | }); 393 | describe('sendContact', () => { 394 | it('should get the response for sendContact', (done) => { 395 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 396 | service 397 | .sendContact({ 398 | chat_id: 8754, 399 | first_name: 'firstName', 400 | last_name: 'lastName', 401 | phone_number: '9876543210', 402 | vcard: 'vcard data', 403 | }) 404 | .subscribe(telegramObserver(done, message, 1)); 405 | }); 406 | }); 407 | describe('sendPoll', () => { 408 | it('should get the response for sendPoll', (done) => { 409 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 410 | service 411 | .sendPoll({ 412 | chat_id: 8754, 413 | question: 'A question for you?', 414 | options: ['answer 1', 'answer 2'], 415 | }) 416 | .subscribe(telegramObserver(done, message, 1)); 417 | }); 418 | }); 419 | describe('sendChatAction', () => { 420 | it('should get the response for senChatAction', (done) => { 421 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 422 | service 423 | .sendChatAction({ 424 | chat_id: 8754, 425 | action: 'some action', 426 | }) 427 | .subscribe(telegramObserver(done, true, 1)); 428 | }); 429 | }); 430 | describe('getUserProfilePhotos', () => { 431 | it('should get the response for getUserProfilePictures', (done) => { 432 | const userPhotos: TelegramUserProfilePhotos = { 433 | total_count: 5, 434 | photos: [[]], 435 | }; 436 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(userPhotos)))); 437 | service 438 | .getUserProfilePhotos({ 439 | user_id: 87542, 440 | offset: 0, 441 | }) 442 | .subscribe(telegramObserver(done, userPhotos, 1)); 443 | }); 444 | }); 445 | describe('getFile', () => { 446 | it('should get the response for getFile', (done) => { 447 | const file: TelegramFile = { 448 | file_id: 'file id', 449 | }; 450 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(file)))); 451 | service 452 | .getFile({ 453 | file_id: 'file id', 454 | }) 455 | .subscribe(telegramObserver(done, file, 1)); 456 | }); 457 | }); 458 | describe('kickChatMember', () => { 459 | it('should get the response for kickChatMember', (done) => { 460 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 461 | service 462 | .kickChatMember({ 463 | user_id: 8754, 464 | chat_id: 'chat id', 465 | }) 466 | .subscribe(telegramObserver(done, true, 1)); 467 | }); 468 | }); 469 | describe('unbanChatMember', () => { 470 | it('should get the response for unbanChatMember', (done) => { 471 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 472 | service 473 | .unbanChatMember({ 474 | chat_id: 8754, 475 | user_id: 9865, 476 | }) 477 | .subscribe(telegramObserver(done, true, 1)); 478 | }); 479 | }); 480 | describe('restrictChatMember', () => { 481 | it('should get the response for restrictChatMember', (done) => { 482 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 483 | service 484 | .restrictChatMember({ 485 | chat_id: 8754, 486 | user_id: 9865, 487 | }) 488 | .subscribe(telegramObserver(done, true, 1)); 489 | }); 490 | }); 491 | describe('promoteChatMember', () => { 492 | it('should get the response for promoteChatMember', (done) => { 493 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 494 | service 495 | .promoteChatMember({ 496 | chat_id: 8754, 497 | user_id: 9865, 498 | }) 499 | .subscribe(telegramObserver(done, true, 1)); 500 | }); 501 | }); 502 | describe('exportChatInviteLink', () => { 503 | it('should get the response for exportChatInviteLink', (done) => { 504 | postMock.mockReturnValueOnce( 505 | of(axiosRes(telegramRes('some invite link'))), 506 | ); 507 | service 508 | .exportChatInviteLink({ 509 | chat_id: 8754, 510 | }) 511 | .subscribe(telegramObserver(done, 'some invite link', 1)); 512 | }); 513 | }); 514 | describe('setChatPhoto', () => { 515 | it('should get the response for setChatPhoto (multipart)', (done) => { 516 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 517 | service 518 | .setChatPhoto({ 519 | chat_id: 8754, 520 | photo: Buffer.alloc(10), 521 | }) 522 | .subscribe(telegramObserver(done, true, 1, multiPartHeader)); 523 | }); 524 | }); 525 | describe('deleteChatPhot', () => { 526 | it('should get the response for deleteChatPhoto', (done) => { 527 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 528 | service 529 | .deleteChatPhoto({ 530 | chat_id: 8754, 531 | }) 532 | .subscribe(telegramObserver(done, true, 1)); 533 | }); 534 | }); 535 | describe('setChatTitle', () => { 536 | it('should get the response for setChatTitle', (done) => { 537 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 538 | service 539 | .setChatTitle({ 540 | chat_id: 8754, 541 | title: 'the chat title', 542 | }) 543 | .subscribe(telegramObserver(done, true, 1)); 544 | }); 545 | }); 546 | describe('setChatDescription', () => { 547 | it('should get the response for setChatDescription', (done) => { 548 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 549 | service 550 | .setChatDescription({ 551 | chat_id: 8754, 552 | description: 'the chat description', 553 | }) 554 | .subscribe(telegramObserver(done, true, 1)); 555 | }); 556 | }); 557 | describe('pinChatMessage', () => { 558 | it('should get the response for pinChatMessage', (done) => { 559 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 560 | service 561 | .pinChatMessage({ 562 | chat_id: 8754, 563 | message_id: 5, 564 | }) 565 | .subscribe(telegramObserver(done, true, 1)); 566 | }); 567 | }); 568 | describe('unpinChatMessage', () => { 569 | it('should get the response for unpinChatMessage', (done) => { 570 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 571 | service 572 | .unpinChatMessage({ 573 | chat_id: 8754, 574 | message_id: 5, 575 | }) 576 | .subscribe(telegramObserver(done, true, 1)); 577 | }); 578 | }); 579 | describe('leaveChat', () => { 580 | it('should get the response for leaveChat', (done) => { 581 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 582 | service 583 | .leaveChat({ 584 | chat_id: 8754, 585 | }) 586 | .subscribe(telegramObserver(done, true, 1)); 587 | }); 588 | }); 589 | describe('getChat', () => { 590 | it('should get the response for getChat', (done) => { 591 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(chat)))); 592 | service 593 | .getChat({ 594 | chat_id: 5421, 595 | }) 596 | .subscribe(telegramObserver(done, chat, 1)); 597 | }); 598 | }); 599 | describe('getChatAdministrators', () => { 600 | it('should get the response for getChatAdministrators', (done) => { 601 | const chatAdmins: TelegramChatMember[] = [ 602 | { 603 | user, 604 | status: 'creator', 605 | }, 606 | ]; 607 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(chatAdmins)))); 608 | service 609 | .getChatAdministrators({ 610 | chat_id: 8754, 611 | }) 612 | .subscribe(telegramObserver(done, chatAdmins, 1)); 613 | }); 614 | }); 615 | describe('getChatMembersCount', () => { 616 | it('should get the response of getChatMembersCount', (done) => { 617 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(5)))); 618 | service 619 | .getChatMembersCount({ 620 | chat_id: 854, 621 | }) 622 | .subscribe(telegramObserver(done, 5, 1)); 623 | }); 624 | }); 625 | describe('getChatMember', () => { 626 | it('should get the response for getChatMember', (done) => { 627 | const chatMember: TelegramChatMember = { 628 | user, 629 | status: 'member', 630 | }; 631 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(chatMember)))); 632 | service 633 | .getChatMember({ 634 | chat_id: 8754, 635 | user_id: 6532, 636 | }) 637 | .subscribe(telegramObserver(done, chatMember, 1)); 638 | }); 639 | }); 640 | describe('setChatStickerSet', () => { 641 | it('should get the response of setChatStickerSet', (done) => { 642 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 643 | service 644 | .setChatStickerSet({ 645 | chat_id: 8754, 646 | sticker_set_name: 'name of set', 647 | }) 648 | .subscribe(telegramObserver(done, true, 1)); 649 | }); 650 | }); 651 | describe('deleteChatStickerSet', () => { 652 | it('should get the response for deleteChatStickerSet', (done) => { 653 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 654 | service 655 | .deleteChatStickerSet({ 656 | chat_id: 8754, 657 | }) 658 | .subscribe(telegramObserver(done, true, 1)); 659 | }); 660 | }); 661 | describe('answerCallbackQuery', () => { 662 | it('should get the response for answerCallbackQuery', (done) => { 663 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 664 | service 665 | .answerCallbackQuery({ 666 | callback_query_id: 'callback query id', 667 | }) 668 | .subscribe(telegramObserver(done, true, 1)); 669 | }); 670 | }); 671 | describe('editMessageText', () => { 672 | it('should get the response for editMessageText(message)', (done) => { 673 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 674 | service 675 | .editMessageText({ 676 | message_id: 5465, 677 | text: 'new message text', 678 | }) 679 | .subscribe(telegramObserver(done, message, 1)); 680 | }); 681 | it('should get the response for editMessageText(true)', (done) => { 682 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 683 | service 684 | .editMessageText({ 685 | message_id: 5465, 686 | text: 'new message text', 687 | }) 688 | .subscribe(telegramObserver(done, true, 1)); 689 | }); 690 | }); 691 | describe('editMessageCaption', () => { 692 | it('should get the response of editMessageCaption(message)', (done) => { 693 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 694 | service 695 | .editMessageCaption({ 696 | message_id: 98754, 697 | reply_markup: { 698 | inline_keyboard: [[]], 699 | }, 700 | }) 701 | .subscribe(telegramObserver(done, message, 1)); 702 | }); 703 | it('should get the response of editMessageCaption(true)', (done) => { 704 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 705 | service 706 | .editMessageCaption({ 707 | message_id: 98754, 708 | reply_markup: { 709 | inline_keyboard: [[]], 710 | }, 711 | }) 712 | .subscribe(telegramObserver(done, true, 1)); 713 | }); 714 | }); 715 | describe('editMessageMedia', () => { 716 | it('should get the response for editMessageMedia(message)', (done) => { 717 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 718 | service 719 | .editMessageMedia({ 720 | message_id: 54321, 721 | media: { 722 | type: 'photo', 723 | media: Buffer.alloc(10), 724 | }, 725 | }) 726 | .subscribe(telegramObserver(done, message, 1)); 727 | }); 728 | it('should get the response for editMessageMedia(true)', (done) => { 729 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 730 | service 731 | .editMessageMedia({ 732 | message_id: 54321, 733 | media: { 734 | type: 'photo', 735 | media: Buffer.alloc(10), 736 | }, 737 | }) 738 | .subscribe(telegramObserver(done, true, 1)); 739 | }); 740 | }); 741 | describe('editMessageReplyMarkup', () => { 742 | it('should get the response for editMessageReplyMarkup(message)', (done) => { 743 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 744 | service 745 | .editMessageReplyMarkup({ 746 | message_id: 54321, 747 | }) 748 | .subscribe(telegramObserver(done, message, 1)); 749 | }); 750 | it('should get the response for editMessageReplyMarkup(true)', (done) => { 751 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 752 | service 753 | .editMessageReplyMarkup({ 754 | message_id: 54321, 755 | }) 756 | .subscribe(telegramObserver(done, true, 1)); 757 | }); 758 | }); 759 | describe('stopPoll', () => { 760 | it('should get the response for stopPoll', (done) => { 761 | const poll: TelegramPoll = { 762 | id: 'pollId', 763 | question: 'The question', 764 | options: [ 765 | { text: 'option 1', voter_count: 2 }, 766 | { text: 'options 2', voter_count: 5 }, 767 | ], 768 | is_closed: false, 769 | }; 770 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(poll)))); 771 | service 772 | .stopPoll({ 773 | chat_id: 8754, 774 | message_id: 32165, 775 | }) 776 | .subscribe(telegramObserver(done, poll, 1)); 777 | }); 778 | }); 779 | describe('deleteMessage', () => { 780 | it('should get the response for delete message', (done) => { 781 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 782 | service 783 | .deleteMessage({ 784 | chat_id: 8754, 785 | message_id: 54213, 786 | }) 787 | .subscribe(telegramObserver(done, true, 1)); 788 | }); 789 | }); 790 | describe('sendSticker', () => { 791 | it('should get the response for sendSticker(multipart)', (done) => { 792 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 793 | service 794 | .sendSticker({ 795 | chat_id: 8754, 796 | sticker: Buffer.alloc(10), 797 | }) 798 | .subscribe(telegramObserver(done, message, 1, multiPartHeader)); 799 | }); 800 | it('should get the response for sendSticker(string)', (done) => { 801 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 802 | service 803 | .sendSticker({ 804 | chat_id: 8754, 805 | sticker: Buffer.alloc(10).toString(), 806 | }) 807 | .subscribe(telegramObserver(done, message, 1)); 808 | }); 809 | }); 810 | describe('getStickerSet', () => { 811 | it('should get the response for getStickerSet', (done) => { 812 | const stickerSet: TelegramStickerSet = { 813 | name: 'stickers!', 814 | contains_masks: false, 815 | title: 'Stickers!', 816 | stickers: [], 817 | }; 818 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(stickerSet)))); 819 | service 820 | .getStickerSet({ 821 | name: 'stickers!', 822 | }) 823 | .subscribe(telegramObserver(done, stickerSet, 1)); 824 | }); 825 | }); 826 | describe('uploadStickerFile', () => { 827 | it('should get the response for uploadStickerFile', (done) => { 828 | const file: TelegramFile = { 829 | file_id: 'id of the file', 830 | }; 831 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(file)))); 832 | service 833 | .uploadStickerFile({ 834 | png_sticker: Buffer.alloc(10), 835 | user_id: 98765, 836 | }) 837 | .subscribe(telegramObserver(done, file, 1)); 838 | }); 839 | }); 840 | describe('createNewStickerSet', () => { 841 | it('should get the response for createNewStickerSet(multipart)', (done) => { 842 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 843 | service 844 | .createNewStickerSet({ 845 | name: 'newStickerSet', 846 | title: 'newStickerSet', 847 | user_id: 8754, 848 | png_sticker: Buffer.alloc(10), 849 | emojis: '', 850 | }) 851 | .subscribe(telegramObserver(done, true, 1, multiPartHeader)); 852 | }); 853 | it('should get the response for createNewStickerSet(string)', (done) => { 854 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 855 | service 856 | .createNewStickerSet({ 857 | name: 'newStickerSet', 858 | title: 'newStickerSet', 859 | user_id: 8754, 860 | png_sticker: Buffer.alloc(10).toString(), 861 | emojis: '', 862 | }) 863 | .subscribe(telegramObserver(done, true, 1)); 864 | }); 865 | }); 866 | describe('addStickerToSet', () => { 867 | it('should get the response for addStickerToSet(multipart)', (done) => { 868 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 869 | service 870 | .addStickerToSet({ 871 | name: 'newStickerSet', 872 | user_id: 8754, 873 | png_sticker: Buffer.alloc(10), 874 | emojis: '', 875 | }) 876 | .subscribe(telegramObserver(done, true, 1, multiPartHeader)); 877 | }); 878 | it('should get the response for addStickerToSet(string)', (done) => { 879 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 880 | service 881 | .addStickerToSet({ 882 | name: 'newStickerSet', 883 | user_id: 8754, 884 | png_sticker: Buffer.alloc(10).toString(), 885 | emojis: '', 886 | }) 887 | .subscribe(telegramObserver(done, true, 1)); 888 | }); 889 | }); 890 | describe('setStickerPositionInSet', () => { 891 | it('should get the response for setStickerPositionInSet', (done) => { 892 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 893 | service 894 | .setStickerPositionInSet({ 895 | position: 5, 896 | sticker: 'theSticker', 897 | }) 898 | .subscribe(telegramObserver(done, true, 1)); 899 | }); 900 | }); 901 | describe('deleteStickerFromSet', () => { 902 | it('should get the response for deleteStickerFromSet', (done) => { 903 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 904 | service 905 | .deleteStickerFromSet({ 906 | sticker: 'theSticker', 907 | }) 908 | .subscribe(telegramObserver(done, true, 1)); 909 | }); 910 | }); 911 | describe('sendInvoice', () => { 912 | it('should get the response for sendInvoice', (done) => { 913 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 914 | service 915 | .sendInvoice({ 916 | chat_id: 5432, 917 | title: 'Invoice title', 918 | payload: 'the payload', 919 | description: 'The description', 920 | provider_token: 'tokens!', 921 | start_parameter: 'some start param', 922 | currency: 'USD', 923 | prices: [], 924 | }) 925 | .subscribe(telegramObserver(done, message, 1)); 926 | }); 927 | }); 928 | describe('answerShippingQuery', () => { 929 | it('should return the response for answerShippingQuery', (done) => { 930 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 931 | service 932 | .answerShippingQuery({ 933 | shipping_query_id: 'callback id', 934 | ok: true, 935 | }) 936 | .subscribe(telegramObserver(done, true, 1)); 937 | }); 938 | }); 939 | describe('answerPreCheckoutQuery', () => { 940 | it('should return the response for answerPreCheckoutQuery', (done) => { 941 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 942 | service 943 | .answerPreCheckoutQuery({ 944 | pre_checkout_query_id: 'callback id', 945 | ok: true, 946 | }) 947 | .subscribe(telegramObserver(done, true, 1)); 948 | }); 949 | }); 950 | describe('sendGame', () => { 951 | it('should get the response for sendGame', (done) => { 952 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 953 | service 954 | .sendGame({ 955 | chat_id: 9865, 956 | game_short_name: 'short name', 957 | }) 958 | .subscribe(telegramObserver(done, message, 1)); 959 | }); 960 | }); 961 | describe('setGameScore', () => { 962 | it('should get the response for sendGame(message)', (done) => { 963 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(message)))); 964 | service 965 | .setGameScore({ 966 | chat_id: 9865, 967 | score: 98989898, 968 | user_id: 5421, 969 | }) 970 | .subscribe(telegramObserver(done, message, 1)); 971 | }); 972 | it('should get the response for sendGame(true)', (done) => { 973 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(true)))); 974 | service 975 | .setGameScore({ 976 | chat_id: 9865, 977 | score: 98989898, 978 | user_id: 5421, 979 | }) 980 | .subscribe(telegramObserver(done, true, 1)); 981 | }); 982 | }); 983 | describe('getGameHighScore', () => { 984 | it('should get the response for getGameHighScore', (done) => { 985 | const gameScores: TelegramGameHighScore[] = [ 986 | { 987 | score: 875421, 988 | user, 989 | position: 1, 990 | }, 991 | ]; 992 | 993 | postMock.mockReturnValueOnce(of(axiosRes(telegramRes(gameScores)))); 994 | service 995 | .getGameHighScore({ 996 | chat_id: 8754, 997 | user_id: 5421, 998 | }) 999 | .subscribe(telegramObserver(done, gameScores, 1)); 1000 | }); 1001 | }); 1002 | }); 1003 | -------------------------------------------------------------------------------- /src/interfaces/telegramTypes.interface.ts: -------------------------------------------------------------------------------- 1 | import { BadRequestException } from '@nestjs/common'; 2 | 3 | /** 4 | * This object represents an incoming update. 5 | * At most one of the optional parameters can be present in any given update. 6 | * 7 | * @see https://core.telegram.org/bots/api#update 8 | */ 9 | export interface Update { 10 | /** 11 | * The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. 12 | * This ID becomes especially handy if you're using Webhooks, since it allows you to ignore repeated updates or to 13 | * restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, 14 | * then identifier of the next update will be chosen randomly instead of sequentially. 15 | */ 16 | update_id: number; 17 | 18 | /** 19 | * New incoming message of any kind — text, photo, sticker, etc. 20 | */ 21 | message?: TelegramMessage; 22 | 23 | /** 24 | * New version of a message that is known to the bot and was edited 25 | */ 26 | edited_message?: TelegramMessage; 27 | 28 | /** 29 | * New incoming channel post of any kind — text, photo, sticker, etc. 30 | */ 31 | channel_post?: any; 32 | // channel_post?: ChannelPost; 33 | 34 | /** 35 | * New version of a channel post that is known to the bot and was edited 36 | */ 37 | edited_channel_post?: any; 38 | // edited_channel_post?: EditedChannelPost; 39 | 40 | /** 41 | * New incoming inline query 42 | */ 43 | inline_query?: any; 44 | // inline_query?: InlineQuery; 45 | 46 | /** 47 | * The result of an inline query that was chosen by a user and sent to their chat partner. Please see our 48 | * documentation on the feedback collecting for details on how to enable these updates for your bot. 49 | */ 50 | chosen_inline_result?: any; 51 | // chosen_inline_result?: ChosenInlineResult; 52 | 53 | /** 54 | * New incoming callback query 55 | */ 56 | callback_query?: TelegramCallbackQuery; 57 | 58 | /** 59 | * New incoming shipping query. Only for invoices with flexible price 60 | */ 61 | shipping_query?: any; 62 | // shipping_query?: ShoppingQuery; 63 | 64 | /** 65 | * New incoming pre-checkout query. Contains full information about checkout 66 | */ 67 | pre_checkout_query?: any; 68 | // pre_checkout_query?: PreCheckoutQuery; 69 | 70 | /** 71 | * New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot 72 | */ 73 | poll?: TelegramPoll; 74 | 75 | /** 76 | * A user changed their answer in a non-anonymous poll. 77 | * Bots receive new votes only in polls that were sent by the bot itself. 78 | */ 79 | poll_answer?: any; 80 | // poll_answer?: PollAnswer; 81 | 82 | /** 83 | * The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is 84 | * blocked or unblocked by the user. 85 | */ 86 | my_chat_member?: any; 87 | // my_chat_member?: ChatMemberUpdated; 88 | 89 | /** 90 | * A chat member's status was updated in a chat. The bot must be an administrator in the chat and must explicitly 91 | * specify “chat_member” in the list of allowed_updates to receive these updates. 92 | */ 93 | chat_member?: any; 94 | // chat_member?: ChatMemberUpdated; 95 | 96 | /** 97 | * A request to join the chat has been sent. 98 | * The bot must have the can_invite_users administrator right in the chat to receive these updates. 99 | */ 100 | chat_join_request?: any; 101 | // chat_join_request?: ChatJoinRequest; 102 | } 103 | 104 | /** 105 | * This object represents a Telegram user or bot. 106 | */ 107 | export interface TelegramUser { 108 | /** 109 | * Unique identifier for this bot to use 110 | */ 111 | id: number; 112 | /** 113 | * true, if this user is a bot 114 | */ 115 | is_bot: boolean; 116 | /** 117 | * User's or bot's first name 118 | */ 119 | first_name: string; 120 | /** 121 | * _Optional._ User's or bot's last name 122 | */ 123 | last_name?: string; 124 | /** 125 | * _Optional._ User's or bot's username 126 | */ 127 | username?: string; 128 | /** 129 | * _Optional._ [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language 130 | */ 131 | language_code?: string; 132 | } 133 | 134 | /** 135 | * This object represents a Telegram chat. 136 | */ 137 | export interface TelegramChat { 138 | /** 139 | * Unique identifier for this chat. 140 | * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. 141 | * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. 142 | */ 143 | id: number; 144 | /** 145 | * Type of chat, can be either “private”, “group”, “supergroup” or “channel” 146 | */ 147 | type: string; 148 | /** 149 | * _Optional._ Title, for supergroups, channels and group chats 150 | */ 151 | title?: string; 152 | /** 153 | * _Optional._ Username, for private chats, supergroups and channels if available 154 | */ 155 | username?: string; 156 | /** 157 | * _Optional._ First name of the other party in a private chat 158 | */ 159 | first_name?: string; 160 | /** 161 | * _Optional._ Last name of the other party in a private chat 162 | */ 163 | last_name?: string; 164 | /** 165 | * _Optional._ True if a group has ‘All Members Are Admins’ enabled. 166 | */ 167 | all_members_are_administrators?: boolean; 168 | /** 169 | * _Optional._ Chat photo. Returned only in [getChat](https://core.telegram.org/bots/api#getchat) 170 | */ 171 | photo?: TelegramChatPhoto; 172 | /** 173 | * _Optional._ Description, for supergroups and channel chats. 174 | * Returned only in [getChat](https://core.telegram.org/bots/api#getchat) 175 | */ 176 | description?: string; 177 | /** 178 | * _Optional._ Chat invite link, for supergroups and channel chats. 179 | * Each administrator in a chat generates their own invite links, 180 | * so the bot must first generate the link using [exportChatInviteLink](https://core.telegram.org/bots/api#exportchatinvitelink). 181 | * Returned only in [getChat](https://core.telegram.org/bots/api#getchat). 182 | */ 183 | invite_link?: string; 184 | /** 185 | * _Optional._ Pinned message, for groups, supergroups and channels. 186 | * Returned only in [getChat](https://core.telegram.org/bots/api#getchat). 187 | */ 188 | pinned_message?: TelegramMessage; 189 | /** 190 | * _Optional._ For supergroups, name of group sticker set. Returned only in [getChat](https://core.telegram.org/bots/api#getchat). 191 | */ 192 | sticker_set_name?: string; 193 | /** 194 | * _Optional._ True, if the bot can change the group sticker set. Returned only in [getChat](https://core.telegram.org/bots/api#getchat). 195 | */ 196 | can_set_sticker_set?: boolean; 197 | } 198 | 199 | export interface TelegramMessage { 200 | /** 201 | * Unique message identifier inside this chat 202 | */ 203 | message_id: number; 204 | /** 205 | * _Optional._ Sender, empty for messages sent to channels 206 | */ 207 | from?: TelegramUser; 208 | /** 209 | * Date the message was sent in Unix time 210 | */ 211 | date: number; 212 | /** 213 | * Conversation the message belongs to 214 | */ 215 | chat: TelegramChat; 216 | /** 217 | * _Optional._ For forwarded messages, sender of the original message 218 | */ 219 | forward_from?: TelegramUser; 220 | /** 221 | * _Optional._ For messages forwarded from channels, information about the original channel 222 | */ 223 | forward_from_chat?: TelegramChat; 224 | /** 225 | * _Optional._ For messages forwarded from channels, identifier of the original message in the channel 226 | */ 227 | forward_from_message_id?: number; 228 | /** 229 | * _Optional._ For messages forwarded from channels, signature of the post author if present 230 | */ 231 | forward_signature?: string; 232 | /** 233 | * _Optional._ Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages 234 | */ 235 | forward_sender_name?: string; 236 | /** 237 | * _Optional._ For forwarded messages, date the original message was sent in Unix time 238 | */ 239 | forward_date?: number; 240 | /** 241 | * _Optional._ For replies, the original message. Note that the 242 | * Message object in this field will not contain further reply_to_message fields even if it itself is a reply. 243 | */ 244 | reply_to_message?: TelegramMessage; 245 | /** 246 | * _Optional._ Date the message was last edited in Unix time 247 | */ 248 | edit_date?: number; 249 | /** 250 | * _Optional._ The unique identifier of a media message group this message belongs to 251 | */ 252 | media_group_id?: string; 253 | /** 254 | * _Optional._ Signature of the post author for messages in channels 255 | */ 256 | author_signature?: string; 257 | /** 258 | * _Optional._ For text messages, the actual UTF-8 text of the message, 0-4096 characters. 259 | */ 260 | text?: string; 261 | /** 262 | * _Optional._ For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text 263 | */ 264 | entities?: TelegramMessageEntity[]; 265 | /** 266 | * _Optional._ For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption 267 | */ 268 | caption_entities?: TelegramMessageEntity[]; 269 | /** 270 | * _Optional._ Message is an audio file, information about the file 271 | */ 272 | audio?: TelegramAudio; 273 | /** 274 | * _Optional._ Message is a general file, information about the file 275 | */ 276 | document?: TelegramDocument; 277 | /** 278 | * _Optional._ Message is an animation, information about the animation. 279 | * For backward compatibility, when this field is set, the document field will also be set 280 | */ 281 | animation?: TelegramAnimation; 282 | /** 283 | * _Optional._ Message is a game, information about the game. [More about games »](https://core.telegram.org/bots/api#games) 284 | */ 285 | game?: TelegramGame; 286 | /** 287 | * _Optional._ Message is a photo, available sizes of the photo 288 | */ 289 | photo?: TelegramPhotoSize[]; 290 | /** 291 | * _Optional._ Message is a sticker, information about the sticker 292 | */ 293 | sticker?: TelegramSticker; 294 | /** 295 | * _Optional._ Message is a video, information about the video 296 | */ 297 | video?: TelegramVideo; 298 | /** 299 | * _Optional._ Message is a voice message, information about the file 300 | */ 301 | voice?: TelegramVoice; 302 | /** 303 | * _Optional._ Message is a [video note](https://telegram.org/blog/video-messages-and-telescope), information about the video message 304 | */ 305 | video_note?: TelegramVideoNote; 306 | /** 307 | * _Optional._ Caption for the animation, audio, document, photo, video or voice, 0-1024 characters 308 | */ 309 | caption?: string; 310 | /** 311 | * _Optional._ Message is a shared contact, information about the contact 312 | */ 313 | contact?: TelegramContact; 314 | /** 315 | * _Optional._ Message is a shared location, information about the location 316 | */ 317 | location?: TelegramLocation; 318 | /** 319 | * _Optional._ Message is a venue, information about the venue 320 | */ 321 | venue?: TelegramVenue; 322 | /** 323 | * _Optional._ Message is a native poll, information about the pol 324 | */ 325 | poll?: TelegramPoll; 326 | /** 327 | * _Optional._ New members that were added to the group 328 | * or supergroup and information about them (the bot itself may be one of these members) 329 | */ 330 | new_chat_members?: TelegramUser[]; 331 | /** 332 | * _Optional._ A member was removed from the group, information about them (this member may be the bot itself) 333 | */ 334 | left_chat_member?: TelegramUser; 335 | /** 336 | * _Optional._ A chat title was changed to this value 337 | */ 338 | new_chat_title?: string; 339 | /** 340 | * _Optional._ A chat photo was change to this value 341 | */ 342 | new_chat_photo?: TelegramPhotoSize[]; 343 | /** 344 | * _Optional._ Service message: the chat photo was deleted 345 | */ 346 | delete_chat_photo?: true; 347 | /** 348 | * _Optional._ Service message: the group has been created 349 | */ 350 | group_chat_deleted?: true; 351 | /** 352 | * _Optional._ Service message: the supergroup has been created. 353 | * This field can‘t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. 354 | * It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. 355 | */ 356 | supergroup_chat_deleted?: true; 357 | /** 358 | * _Optional._ Service message: the channel has been created. 359 | * This field can‘t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. 360 | * It can only be found in reply_to_message if someone replies to a very first message in a channel. 361 | */ 362 | channel_chat_created?: true; 363 | /** 364 | * _Optional._ The group has been migrated to a supergroup with the specified identifier. 365 | * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. 366 | * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. 367 | */ 368 | migrate_to_chat_id?: number; 369 | /** 370 | * _Optional._ The supergroup has been migrated from a group with the specified identifier. 371 | * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. 372 | * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. 373 | */ 374 | migrate_from_chat_id?: number; 375 | /** 376 | * _Optional._ Specified message was pinned. 377 | * Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. 378 | */ 379 | pinned_message?: TelegramMessage; 380 | /** 381 | * _Optional._ Message is an invoice for a [payment](https://core.telegram.org/bots/api#payments), 382 | * information about the invoice. 383 | * [More about payments »](https://core.telegram.org/bots/api#payments) 384 | */ 385 | invoice?: TelegramInvoice; 386 | /** 387 | * _Optional._ Message is a service message about a successful payment, information about the payment. 388 | * [More about payments »](https://core.telegram.org/bots/api#payments) 389 | */ 390 | successful_payment?: TelegramSuccessfulPayment; 391 | /** 392 | * _Optional._ The domain name of the website on which the user has logged in. 393 | * [More about Login »](https://core.telegram.org/widgets/login) 394 | */ 395 | connected_website?: string; 396 | /** 397 | * _Optional._ Passport data 398 | */ 399 | passport_data?: TelegramPassportData; 400 | /** 401 | * Optional. Inline keyboard attached to the message. `login_url` buttons are represented as ordinary `url` buttons. 402 | */ 403 | reply_markup?: TelegramInlineKeyboardMarkup; 404 | } 405 | 406 | /** 407 | * This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. 408 | */ 409 | export interface TelegramMessageEntity { 410 | /** 411 | * Type of the entity. 412 | * Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), 413 | * italic (italic text), code (monowidth string), pre (monowidth block), 414 | * text_link (for clickable text URLs), text_mention (for users [without usernames](https://telegram.org/blog/edit#new-mentions)) 415 | */ 416 | type: string; 417 | /** 418 | * Offset in UTF-16 code units to the start of the entity 419 | */ 420 | offset: number; 421 | /** 422 | * Length of the entity in UTF-16 code units 423 | */ 424 | length: number; 425 | /** 426 | * _Optional._ For “text_link” only, url that will be opened after user taps on the text 427 | */ 428 | url?: string; 429 | /** 430 | * _Optional._ For “text_mention” only, the mentioned user 431 | */ 432 | user?: TelegramUser; 433 | } 434 | 435 | /** 436 | * This object represents one size of a photo or a [file](https://core.telegram.org/bots/api#document) / 437 | * [sticker](https://core.telegram.org/bots/api#sticker) thumbnail. 438 | */ 439 | export interface TelegramPhotoSize { 440 | /** 441 | * Unique identifier for this file 442 | */ 443 | file_id: string; 444 | /** 445 | * Photo width 446 | */ 447 | width: number; 448 | /** 449 | * Photo height 450 | */ 451 | height: number; 452 | /** 453 | * _Optional._ File size 454 | */ 455 | file_size: number; 456 | } 457 | 458 | /** 459 | * This object represents an audio file to be treated as music by the clients. 460 | */ 461 | export interface TelegramAudio { 462 | /** 463 | * Unique identifier for this file 464 | */ 465 | file_id: string; 466 | /** 467 | * Duration of the audio in seconds as defined by sender 468 | */ 469 | duration: number; 470 | /** 471 | * _Optional._ Performer of the audio as defined by sender or by audio tags 472 | */ 473 | performer?: string; 474 | /** 475 | * _Optional._ Title of the audio as defined by sender or by audio tags 476 | */ 477 | title?: string; 478 | /** 479 | * _Optional._ MIME type of the file as defined by sender 480 | */ 481 | mime_type?: string; 482 | /** 483 | * _Optional._ File size 484 | */ 485 | file_size?: number; 486 | /** 487 | * _Optional._ Thumbnail of the album cover to which the music file belongs 488 | */ 489 | thumb?: TelegramPhotoSize; 490 | } 491 | 492 | /** 493 | * This object represents a general file (as opposed to [photos](https://core.telegram.org/bots/api#photosize), 494 | * [voice messages](https://core.telegram.org/bots/api#voice) 495 | * and [audio files](https://core.telegram.org/bots/api#audio)). 496 | */ 497 | export interface TelegramDocument { 498 | /** 499 | * Unique file identifier 500 | */ 501 | file_id: string; 502 | /** 503 | * _Optional._ Document thumbnail as defined by sender 504 | */ 505 | thumb?: TelegramPhotoSize; 506 | /** 507 | * _Optional._ Original filename as defined by sender 508 | */ 509 | file_name?: string; 510 | /** 511 | * _Optional._ MIME type of the file as defined by sender 512 | */ 513 | mime_type?: string; 514 | /** 515 | * _Optional._ File size 516 | */ 517 | file_size?: number; 518 | } 519 | 520 | /** 521 | * This object represents a video file. 522 | */ 523 | export interface TelegramVideo { 524 | /** 525 | * Unique identifier for this file 526 | */ 527 | file_id: string; 528 | /** 529 | * Video width as defined by sender 530 | */ 531 | width: number; 532 | /** 533 | * Video height as defined by sender 534 | */ 535 | height: number; 536 | /** 537 | * Duration of the video in seconds as defined by sender 538 | */ 539 | duration: number; 540 | /** 541 | * _Optional._ Video thumbnail 542 | */ 543 | thumb?: TelegramPhotoSize; 544 | /** 545 | * _Optional._ Mime type of a file as defined by sender 546 | */ 547 | mime_type?: string; 548 | /** 549 | * _Optional._ File size 550 | */ 551 | file_size?: number; 552 | } 553 | 554 | /** 555 | * This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). 556 | */ 557 | export interface TelegramAnimation { 558 | /** 559 | * Unique file identifier 560 | */ 561 | file_id: string; 562 | /** 563 | * Video width as defined by sender 564 | */ 565 | width: number; 566 | /** 567 | * Video height as defined by sender 568 | */ 569 | height: number; 570 | /** 571 | * Duration of the video in seconds as defined by sender 572 | */ 573 | duration: number; 574 | /** 575 | * _Optional._ Animation thumbnail as defined by sender 576 | */ 577 | thumb?: TelegramPhotoSize; 578 | /** 579 | * _Optional._ Original animation filename as defined by sender 580 | */ 581 | file_name?: string; 582 | /** 583 | * _Optional._ MIME type of the file as defined by sender 584 | */ 585 | mime_type?: string; 586 | /** 587 | * _Optional._ File size 588 | */ 589 | file_size?: number; 590 | } 591 | 592 | /** 593 | * This object represents a voice note. 594 | */ 595 | export interface TelegramVoice { 596 | /** 597 | * Unique identifier for this file 598 | */ 599 | file_id: string; 600 | /** 601 | * Duration of the audio in seconds as defined by sender 602 | */ 603 | duration: number; 604 | /** 605 | * _Optional._ MIME type of the file as defined by sender 606 | */ 607 | mime_type?: string; 608 | /** 609 | * _Optional._ File size 610 | */ 611 | file_size?: number; 612 | } 613 | 614 | /** 615 | * This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope) 616 | * (available in apps as of [v.4.0](https://telegram.org/blog/video-messages-and-telescope)). 617 | */ 618 | export interface TelegramVideoNote { 619 | /** 620 | * Unique identifier for this file 621 | */ 622 | file_id: string; 623 | /** 624 | * Video width and height (diameter of the video message) as defined by sender 625 | */ 626 | length: number; 627 | /** 628 | * Duration of the video in seconds as defined by sender 629 | */ 630 | duration: number; 631 | /** 632 | * _Optional._ Video thumbnail 633 | */ 634 | thumb?: TelegramPhotoSize; 635 | /** 636 | * _Optional._ File size 637 | */ 638 | file_size?: number; 639 | } 640 | 641 | /** 642 | * This object represents a phone contact. 643 | */ 644 | export interface TelegramContact { 645 | /** 646 | * Contact's phone number 647 | */ 648 | phone_number: string; 649 | /** 650 | * Contact's first name 651 | */ 652 | first_name: string; 653 | /** 654 | * _Optional._ Contact's last name 655 | */ 656 | last_name: string; 657 | /** 658 | * _Optional._ Contact's user identifier in Telegram 659 | */ 660 | user_id: number; 661 | /** 662 | * _Optional._ Additional data about the contact in the form of a [vCard](https://en.wikipedia.org/wiki/VCard) 663 | */ 664 | vcard: string; 665 | } 666 | 667 | /** 668 | * This object represents a point on the map. 669 | */ 670 | export interface TelegramLocation { 671 | /** 672 | * Longitude as defined by sender 673 | */ 674 | longitude: number; 675 | /** 676 | * Latitude as defined by sender 677 | */ 678 | latitude: number; 679 | } 680 | 681 | /** 682 | * This object represents a venue. 683 | */ 684 | export interface TelegramVenue { 685 | /** 686 | * Venue location 687 | */ 688 | location: TelegramLocation; 689 | /** 690 | * Name of the venue 691 | */ 692 | title: string; 693 | /** 694 | * Address of the venue 695 | */ 696 | address: string; 697 | /** 698 | * _Optional._ Foursquare identifier of the venue 699 | */ 700 | foursqaure_id?: string; 701 | /** 702 | * _Optional._ Foursquare type of the venue. 703 | * (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 704 | */ 705 | foursquare_type?: string; 706 | } 707 | 708 | /** 709 | * This object contains information about one answer option in a poll. 710 | */ 711 | export interface TelegramPollOption { 712 | /** 713 | * Option text, 1-100 characters 714 | */ 715 | text: string; 716 | /** 717 | * Number of users that voted for this option 718 | */ 719 | voter_count: number; 720 | } 721 | 722 | /** 723 | * This object contains information about a poll. 724 | */ 725 | export interface TelegramPoll { 726 | /** 727 | * Unique poll identifier 728 | */ 729 | id: string; 730 | /** 731 | * Poll question, 1-255 characters 732 | */ 733 | question: string; 734 | /** 735 | * List of poll options 736 | */ 737 | options: TelegramPollOption[]; 738 | /** 739 | * True, if the poll is closed 740 | */ 741 | is_closed: boolean; 742 | } 743 | 744 | /** 745 | * This object represent a user's profile pictures. 746 | */ 747 | export interface TelegramUserProfilePhotos { 748 | /** 749 | * Total number of profile pictures the target user has 750 | */ 751 | total_count: number; 752 | /** 753 | * Requested profile pictures (in up to 4 sizes each) 754 | */ 755 | photos: TelegramPhotoSize[][]; 756 | } 757 | 758 | /** 759 | * This object represents a file ready to be downloaded. 760 | * The file can be downloaded via the link `https://api.telegram.org/file/bot/`. 761 | * It is guaranteed that the link will be valid for at least 1 hour. 762 | * When the link expires, a new one can be requested by calling getFile. 763 | * 764 | * > Maximum file size to download is 20 MB 765 | */ 766 | export interface TelegramFile { 767 | /** 768 | * Unique identifier for this file 769 | */ 770 | file_id: string; 771 | /** 772 | * _Optional._ File size, if known 773 | */ 774 | file_size?: number; 775 | /** 776 | * _Optional._ File path. Use `https://api.telegram.org/file/bot/` to get the file. 777 | */ 778 | file_path?: string; 779 | } 780 | 781 | /** 782 | * This object represents a [custom keyboard](https://core.telegram.org/bots#keyboards) with reply options 783 | * (see [Introduction to bots](https://core.telegram.org/bots#keyboards) for details and examples). 784 | */ 785 | export interface TelegramReplyKeyboardMarkup { 786 | /** 787 | * Array of button rows, each represented by an Array of [KeyboardButton](https://core.telegram.org/bots/api#keyboardbutton) objects 788 | */ 789 | keyboard: TelegramKeyboardButton[][]; 790 | /** 791 | * _Optional._Requests clients to resize the keyboard vertically for optimal fit 792 | * (e.g., make the keyboard smaller if there are just two rows of buttons). 793 | * Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. 794 | */ 795 | resize_keyboard?: boolean; 796 | /** 797 | * _Optional._ Requests clients to hide the keyboard as soon as it's been used. 798 | * The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - 799 | * the user can press a special button in the input field to see the custom keyboard again. Defaults to false. 800 | */ 801 | one_time_keyboard?: boolean; 802 | /** 803 | * _Optional._ Use this parameter if you want to show the keyboard to specific users only. Targets: 804 | * 805 | * 1) users that are @mentioned in the text of the [Message](https://core.telegram.org/bots/api#messagec) object; 806 | * 807 | * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. 808 | * 809 | * __Example:__ A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. 810 | * Other users in the group don’t see the keyboard. 811 | */ 812 | selective?: boolean; 813 | } 814 | 815 | /** 816 | * This object represents one button of the reply keyboard. 817 | * For simple text buttons String can be used instead of this object to specify text of the button. 818 | * Optional fields are mutually exclusive. 819 | * 820 | * > __Note:__ request_contact and request_location options will only work in 821 | * versions released after 9 April, 2016. Older clients will ignore them. 822 | */ 823 | export interface TelegramKeyboardButton { 824 | /** 825 | * Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed 826 | */ 827 | text: string; 828 | /** 829 | * _Optional._ If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only 830 | */ 831 | request_contact?: boolean; 832 | /** 833 | * _Optional._ If True, the user's current location will be sent when the button is pressed. Available in private chats only 834 | */ 835 | request_location?: boolean; 836 | } 837 | 838 | /** 839 | * Upon receiving a message with this object, clients will remove the current custom keyboard and display the 840 | * default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. 841 | * An exception is made for one-time keyboards that are hidden immediately after the user presses a button 842 | * (see [ReplyKeyboardMarkup](https://core.telegram.org/bots/api#replykeyboardmarkup)). 843 | */ 844 | export interface TelegramReplyKeyboardRemove { 845 | /** 846 | * Requests clients to remove the custom keyboard (user will not be able to summon 847 | * this keyboard; if you want to hide the keyboard from sight but keep it accessible, use _one_time_keyboard_ in 848 | * [ReplyKeyboardMarkup](https://core.telegram.org/bots/api#replykeyboardmarkup)) 849 | */ 850 | remove_keyboard: true; 851 | /** 852 | * _Optional._ Use this parameter if you want to remove the keyboard for specific users only. Targets: 853 | * 854 | * 1) users that are @mentioned in the text of the [Message](https://core.telegram.org/bots/api#message) object; 855 | * 856 | * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. 857 | * 858 | * __Example:__ A user votes in a poll, bot returns confirmation message in reply to the vote and removes the 859 | * keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. 860 | */ 861 | selective?: boolean; 862 | } 863 | 864 | /** 865 | * This object represents an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 866 | * that appears right next to the message it belongs to. 867 | * 868 | * > **Note:** This will only work in versions released after 9 April, 2016. Older clients will display _unsupported message_. 869 | */ 870 | export interface TelegramInlineKeyboardMarkup { 871 | /** 872 | * Array of button rows, each represented by an Array of 873 | * [InlineKeyboardButton](https://core.telegram.org/bots/api#inlinekeyboardbutton) objects 874 | */ 875 | inline_keyboard: TelegramInlineKeyboardButton[][]; 876 | } 877 | 878 | /**This object represents one button of an inline keyboard. 879 | * You must use exactly one of the optional fields. 880 | */ 881 | export interface TelegramInlineKeyboardButton { 882 | /** 883 | * Label text on the button 884 | */ 885 | text: string; 886 | /** 887 | * _Optional._ HTTP or tg:// url to be opened when button is pressed 888 | */ 889 | url?: string; 890 | /** 891 | * _Optional._ An HTTP URL used to automatically authorize the user. 892 | * Can be used as a replacement for the [ Login Widget](https://core.telegram.org/widgets/login). 893 | */ 894 | login_url?: TelegramLoginUrl; 895 | /** 896 | * _Optional._ Data to be sent in a [callback query](https://core.telegram.org/bots/api#callbackquery) to 897 | * the bot when button is pressed, 1-64 bytes 898 | */ 899 | callback_data?: string; 900 | /** 901 | * _Optional._ If set, pressing the button will prompt the user to select one of their chats, open that chat and insert 902 | * the bot‘s username and the specified inline query in the input field. 903 | * Can be empty, in which case just the bot’s username will be inserted. 904 | * 905 | * **Note:** This offers an easy way for users to start using your bot in 906 | * inline mode when they are currently in a private chat with it. 907 | * Especially useful when combined with switch_pm… actions – in this case 908 | * the user will be automatically returned to the chat they switched from, skipping the chat selection screen. 909 | */ 910 | switch_inline_query?: string; 911 | /** 912 | * _Optional._ If set, pressing the button will insert the bot‘s username and the 913 | * specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. 914 | * 915 | * This offers a quick way for the user to open your bot in inline mode in the same chat – 916 | * good for selecting something from multiple options. 917 | */ 918 | switch_inline_query_current_chat?: string; 919 | /** 920 | * _Optional._ Description of the game that will be launched when the user presses the button. 921 | * 922 | * **NOTE:** This type of button **must** always be the first button in the first row. 923 | */ 924 | callback_game?: TelegramCallbackGame; 925 | /** 926 | * _Optional._ Specify True, to send a [Pay button](https://core.telegram.org/bots/api#payments). 927 | * 928 | * **NOTE:** This type of button **must** always be the first button in the first row. 929 | */ 930 | pay?: boolean; 931 | } 932 | 933 | /** 934 | * This object represents a parameter of the inline keyboard button used to automatically authorize a user. Serves as a great 935 | * replacement for the [ Login Widget](https://core.telegram.org/widgets/login) 936 | * when the user is coming from . All the user needs to do is tap/click a button and confirm that they want to log in: 937 | * 938 | * apps support these buttons as of [version 5.7.](https://telegram.org/blog/privacy-discussions-web-bots#meet-seamless-web-bots) 939 | * 940 | * > Sample bot: [@discussbot](https://t.me/discussbot) 941 | */ 942 | export interface TelegramLoginUrl { 943 | /** 944 | * An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. 945 | * If the user refuses to provide authorization data, the original URL without information about the user will be opened. 946 | * The data added is the same as described in 947 | * [Receiving authorization data.](https://core.telegram.org/widgets/login#receiving-authorization-data) 948 | * 949 | * **NOTE:** You **must** always check the hash of the received data to verify the 950 | * authentication and the integrity of the data as described in 951 | * [Checking authorization.](https://core.telegram.org/widgets/login#checking-authorization) 952 | */ 953 | url: string; 954 | /** 955 | * _Optional._ New text of the button in forwarded messages. 956 | */ 957 | forward_text?: string; 958 | /** 959 | * _Optional._ Username of a bot, which will be used for user authorization. See 960 | * [Setting up a bot](https://core.telegram.org/widgets/login#setting-up-a-bot) 961 | * for more details. If not specified, the current bot's username will be assumed. 962 | * The url's domain must be the same as the domain linked with the bot. 963 | * See [Linking your domain to the bot](https://core.telegram.org/widgets/login#linking-your-domain-to-the-bot) for more details. 964 | */ 965 | bot_username?: string; 966 | /** 967 | * _Optional._ Pass True to request the permission for your bot to send messages to the user. 968 | */ 969 | request_write_access?: boolean; 970 | } 971 | 972 | /** 973 | * This object represents an incoming callback query from a callback button in an 974 | * [inline keyboard.](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 975 | * If the button that originated the query was attached to a message sent by the bot, the field message will be present. 976 | * If the button was attached to a message sent via the bot (in [inline mode](https://core.telegram.org/bots/api#inline-mode)), 977 | * the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present. 978 | * 979 | * > **NOTE:** After the user presses a callback button, 980 | * clients will display a progress bar until you call 981 | * [answerCallbackQuery](https://core.telegram.org/bots/api#answercallbackquery). 982 | * It is, therefore, necessary to react by calling 983 | * [answerCallbackQuery](https://core.telegram.org/bots/api#answercallbackquery) 984 | * even if no notification to the user is needed (e.g., without specifying any of the optional parameters). 985 | */ 986 | export interface TelegramCallbackQuery { 987 | /** 988 | * Unique identifier for this query 989 | */ 990 | id: string; 991 | /** 992 | * Sender 993 | */ 994 | from: TelegramUser; 995 | /** 996 | * _Optional._ Message with the callback button that originated the query. 997 | * Note that message content and message date will not be available if the message is too old 998 | */ 999 | message?: TelegramMessage; 1000 | /** 1001 | * _Optional._ Identifier of the message sent via the bot in inline mode, that originated the query. 1002 | */ 1003 | inline_message_id?: string; 1004 | /** 1005 | * Global identifier, uniquely corresponding to the chat to which the 1006 | * message with the callback button was sent. Useful for high scores in [games](https://core.telegram.org/bots/api#games). 1007 | */ 1008 | chat_instance: string; 1009 | /** 1010 | * _Optional._ Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field. 1011 | */ 1012 | data?: string; 1013 | /** 1014 | * _Optional._ Short name of a [Game](https://core.telegram.org/bots/api#games) 1015 | * to be returned, serves as the unique identifier for the game 1016 | */ 1017 | game_short_name?: string; 1018 | } 1019 | 1020 | /** 1021 | * Upon receiving a message with this object, clients will display a reply interface to the user 1022 | * (act as if the user has selected the bot‘s message and tapped ’Reply'). 1023 | * This can be extremely useful if you want to create user-friendly step-by-step interfaces 1024 | * without having to sacrifice [privacy mode](https://core.telegram.org/bots#privacy-mode). 1025 | * 1026 | * > **Example:** A [poll bot](https://t.me/PollBot) for groups runs in privacy mode 1027 | * (only receives commands, replies to its messages and mentions). 1028 | * There could be two ways to create a new poll: 1029 | * 1030 | * * Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). 1031 | * May be appealing for hardcore users but lacks modern day polish. 1032 | * *Guide the user through a step-by-step process. ‘Please send me your question’, 1033 | * ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’. 1034 | * 1035 | * The last option is definitely more attractive. And if you use [ForceReply](https://core.telegram.org/bots/api#forcereply) 1036 | * in your bot‘s questions, it will receive 1037 | * the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user. 1038 | */ 1039 | export interface TelegramForceReply { 1040 | /** 1041 | * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' 1042 | */ 1043 | force_reply: true; 1044 | /** 1045 | * _Optional._ Use this parameter if you want to force reply from specific users only. Targets: 1046 | * 1047 | * 1) users that are @mentioned in the text of the [Message](https://core.telegram.org/bots/api#message) object; 1048 | * 1049 | * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. 1050 | */ 1051 | selective?: boolean; 1052 | } 1053 | 1054 | /** 1055 | * This object represents a chat photo. 1056 | */ 1057 | export interface TelegramChatPhoto { 1058 | /** 1059 | * Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download. 1060 | */ 1061 | small_file_id: string; 1062 | /** 1063 | * Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. 1064 | */ 1065 | big_file_id: string; 1066 | } 1067 | 1068 | /** 1069 | * This object contains information about one member of a chat. 1070 | */ 1071 | export interface TelegramChatMember { 1072 | /** 1073 | * Information about the user 1074 | */ 1075 | user: TelegramUser; 1076 | /** 1077 | * The member's status in the chat. Can be “creator”, “administrator”, “member”, “restricted”, “left” or “kicked” 1078 | */ 1079 | status: string; 1080 | /** 1081 | * _Optional._ Restricted and kicked only. Date when restrictions will be lifted for this user, unix time 1082 | */ 1083 | until_date?: number; 1084 | /** 1085 | * _Optional._ Administrators only. True, if the bot is allowed to edit administrator privileges of that user 1086 | */ 1087 | can_be_edited?: boolean; 1088 | /** 1089 | * _Optional._ Administrators only. True, if the administrator can change the chat title, photo and other settings 1090 | */ 1091 | can_change_info?: boolean; 1092 | /** 1093 | * _Optional._ Administrators only. True, if the administrator can post in the channel, channels only 1094 | */ 1095 | can_post_messages?: boolean; 1096 | /** 1097 | * _Optional._ Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only 1098 | */ 1099 | can_edit_messages?: boolean; 1100 | /** 1101 | * _Optional._ Administrators only. True, if the administrator can delete messages of other users 1102 | */ 1103 | can_delete_messages?: boolean; 1104 | /** 1105 | * _Optional._ Administrators only. True, if the administrator can invite new users to the chat 1106 | */ 1107 | can_invite_users?: boolean; 1108 | /** 1109 | * _Optional._ Administrators only. True, if the administrator can restrict, ban or unban chat members 1110 | */ 1111 | can_restrict_members?: boolean; 1112 | /** 1113 | * _Optional._ Administrators only. True, if the administrator can pin messages, groups and supergroups only 1114 | */ 1115 | can_pin_messages?: boolean; 1116 | /** 1117 | * _Optional._ Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or 1118 | * demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user) 1119 | */ 1120 | can_promote_members?: boolean; 1121 | /** 1122 | * _Optional._ Restricted only. True, if the user is a member of the chat at the moment of the request 1123 | */ 1124 | is_member?: boolean; 1125 | /** 1126 | * _Optional._ Restricted only. True, if the user can send text messages, contacts, locations and venues 1127 | */ 1128 | can_send_messages?: boolean; 1129 | /** 1130 | * _Optional._ Restricted only. True, if the user can send audios, documents, 1131 | * photos, videos, video notes and voice notes, implies can_send_messages 1132 | */ 1133 | can_send_media_messages?: boolean; 1134 | /** 1135 | * _Optional._ Restricted only. True, if the user can send animations, games, 1136 | * stickers and use inline bots, implies can_send_media_messages 1137 | */ 1138 | can_send_other_messages?: boolean; 1139 | /** 1140 | * _Optional._ Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages 1141 | */ 1142 | can_add_web_page_previews?: boolean; 1143 | } 1144 | 1145 | /** 1146 | * Contains information about why a request was unsuccessful. 1147 | */ 1148 | export interface TelegramResponseParameters { 1149 | /** 1150 | * _Optional._ The group has been migrated to a supergroup with the specified identifier. 1151 | * This number may be greater than 32 bits and some programming languages may 1152 | * have difficulty/silent defects in interpreting it. But it is smaller than 1153 | * 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. 1154 | */ 1155 | migrate_to_chat_id?: number; 1156 | /** 1157 | * _Optional._ In case of exceeding flood control, the number of seconds left to wait before the request can be repeated 1158 | */ 1159 | retry_after?: number; 1160 | } 1161 | 1162 | /** 1163 | * This object represents the content of a media message to be sent. It should be one of 1164 | * * InputMediaAnimation 1165 | * * InputMediaDocument 1166 | * * InputMediaAudio 1167 | * * InputMediaPhoto 1168 | * * InputMediaVideo 1169 | */ 1170 | export interface TelegramInputMedia { 1171 | /** 1172 | * Type of the result, must be audio, photo, video, animation, or document 1173 | */ 1174 | type: string; 1175 | /** 1176 | * File to send. Pass a file_id to send a file that exists on the servers (recommended), 1177 | * pass an HTTP URL for to get a file from the Internet, or pass “attach://” 1178 | * to upload a new one using multipart/form-data under name. 1179 | * [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1180 | */ 1181 | media: Buffer | string; 1182 | /** 1183 | * _Optional._ Caption of the photo to be sent, 0-1024 characters 1184 | */ 1185 | caption?: string; 1186 | /** 1187 | * _Optional._ Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 1188 | * [HTML](https://core.telegram.org/bots/api#html-style), 1189 | * if you want apps to show 1190 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in the media caption. 1191 | */ 1192 | parse_mode?: string; 1193 | } 1194 | 1195 | /** 1196 | * Represents a photo to be sent. 1197 | */ 1198 | export interface TelegramInputMediaPhoto extends TelegramInputMedia { 1199 | /** 1200 | * Type of the result, must be photo 1201 | */ 1202 | type: string; 1203 | } 1204 | 1205 | /** 1206 | * Represents a video to be sent. 1207 | */ 1208 | export interface TelegramInputMediaVideo extends TelegramInputMedia { 1209 | /** 1210 | * Type of the result, must be video 1211 | */ 1212 | type: string; 1213 | /** 1214 | * _Optional._ Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. 1215 | * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. 1216 | * Ignored if the file is not uploaded using multipart/form-data. 1217 | * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” 1218 | * if the thumbnail was uploaded using multipart/form-data under . 1219 | * [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1220 | */ 1221 | thumb?: Buffer | string; 1222 | /** 1223 | * _Optional._ Video width 1224 | */ 1225 | width?: number; 1226 | /** 1227 | * _Optional._ Video height 1228 | */ 1229 | height?: number; 1230 | /** 1231 | * _Optional._ Video duration 1232 | */ 1233 | duration?: number; 1234 | /** 1235 | * _Optional._ Pass True, if the uploaded video is suitable for streaming 1236 | */ 1237 | supports_streaming?: boolean; 1238 | } 1239 | 1240 | /** 1241 | * Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. 1242 | */ 1243 | export interface TelegramInputMediaAnimation extends TelegramInputMedia { 1244 | /** 1245 | * Type of the result, must be animation 1246 | */ 1247 | type: 'animation'; 1248 | /** 1249 | * _Optional._ Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. 1250 | * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. 1251 | * Ignored if the file is not uploaded using multipart/form-data. 1252 | * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” 1253 | * if the thumbnail was uploaded using multipart/form-data under . 1254 | * [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1255 | */ 1256 | thumb?: Buffer | string; 1257 | /** 1258 | * _Optional._ Animation width 1259 | */ 1260 | width?: number; 1261 | /** 1262 | * _Optional._ Animation height 1263 | */ 1264 | height?: number; 1265 | /** 1266 | * _Optional._ Animation duration 1267 | */ 1268 | duration?: number; 1269 | } 1270 | 1271 | /** 1272 | * Represents an audio file to be treated as music to be sent. 1273 | */ 1274 | export interface TelegramInputMediaAudio extends TelegramInputMedia { 1275 | /** 1276 | * Type of the result, must be audio 1277 | */ 1278 | type: 'audio'; 1279 | /** 1280 | * _Optional._ Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. 1281 | * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. 1282 | * Ignored if the file is not uploaded using multipart/form-data. 1283 | * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” 1284 | * if the thumbnail was uploaded using multipart/form-data under . 1285 | * [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1286 | */ 1287 | thumb?: Buffer | string; 1288 | /** 1289 | * _Optional._ Duration of the audio in seconds 1290 | */ 1291 | duration?: number; 1292 | /** 1293 | * _Optional._ Performer of the audio 1294 | */ 1295 | performer?: string; 1296 | /** 1297 | * _Optional._ Title of the audio 1298 | */ 1299 | title?: string; 1300 | } 1301 | 1302 | /** 1303 | * Represents a general file to be sent. 1304 | */ 1305 | export interface TelegramInputMediaDocument extends TelegramInputMedia { 1306 | /** 1307 | * Type of the result, must be document 1308 | */ 1309 | type: 'document'; 1310 | /** 1311 | * _Optional._ Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. 1312 | * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. 1313 | * Ignored if the file is not uploaded using multipart/form-data. 1314 | * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” 1315 | * if the thumbnail was uploaded using multipart/form-data under . 1316 | * [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1317 | */ 1318 | thumb?: Buffer | string; 1319 | } 1320 | 1321 | /************************************* 1322 | * 1323 | * T E L E G R A M S T I C K E R S 1324 | * 1325 | *************************************/ 1326 | 1327 | /** 1328 | * This object represents a sticker. 1329 | */ 1330 | export interface TelegramSticker { 1331 | /** 1332 | * Unique identifier for this file 1333 | */ 1334 | file_id: string; 1335 | /** 1336 | * Sticker width 1337 | */ 1338 | width: number; 1339 | /** 1340 | * Sticker height 1341 | */ 1342 | height: number; 1343 | /** 1344 | * _Optional._ Sticker thumbnail in the .webp or .jpg format 1345 | */ 1346 | thumb?: TelegramPhotoSize; 1347 | /** 1348 | * _Optional._ Emoji associated with the sticker 1349 | */ 1350 | emoji?: string; 1351 | /** 1352 | * _Optional._ Name of the sticker set to which the sticker belongs 1353 | */ 1354 | set_name?: string; 1355 | /** 1356 | * _Optional._ For mask stickers, the position where the mask should be placed 1357 | */ 1358 | mask_position?: TelegramMaskPosition; 1359 | /** 1360 | * _Optional._ File size 1361 | */ 1362 | file_size?: number; 1363 | } 1364 | 1365 | /** 1366 | * This object represents a sticker set. 1367 | */ 1368 | export interface TelegramStickerSet { 1369 | /** 1370 | * Sticker set name 1371 | */ 1372 | name: string; 1373 | /** 1374 | * Sticker set title 1375 | */ 1376 | title: string; 1377 | /** 1378 | * True, if the sticker set contains masks 1379 | */ 1380 | contains_masks: boolean; 1381 | /** 1382 | * List of all set stickers 1383 | */ 1384 | stickers: TelegramSticker[]; 1385 | } 1386 | 1387 | /** 1388 | * This object describes the position on faces where a mask should be placed by default. 1389 | */ 1390 | export interface TelegramMaskPosition { 1391 | /** 1392 | * The part of the face relative to which the mask should be placed. One of “forehead”, “eyes”, “mouth”, or “chin”. 1393 | */ 1394 | point: 'forehead' | 'eyes' | 'mouth' | 'chin'; 1395 | /** 1396 | * Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. 1397 | * For example, choosing -1.0 will place mask just to the left of the default mask position. 1398 | */ 1399 | x_shift: number; 1400 | /** 1401 | * Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. 1402 | * For example, 1.0 will place the mask just below the default mask position. 1403 | */ 1404 | y_shift: number; 1405 | /** 1406 | * Mask scaling coefficient. For example, 2.0 means double size. 1407 | */ 1408 | scale: number; 1409 | } 1410 | 1411 | /************************************* 1412 | * 1413 | * T E L E G R A M P A Y M E N T S 1414 | * 1415 | *************************************/ 1416 | 1417 | /** 1418 | * This object represents a portion of the price for goods or services. 1419 | */ 1420 | export interface TelegramLabeledPrice { 1421 | /** 1422 | * Portion label 1423 | */ 1424 | label: string; 1425 | /** 1426 | * Price of the product in the smallest units of the 1427 | * [currency](https://core.telegram.org/bots/payments#supported-currencies) * (integer, not float/double). 1428 | * For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in 1429 | * [currencies.json](https://core.telegram.org/bots/payments/currencies.json_), 1430 | * it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). 1431 | */ 1432 | amount: number; 1433 | } 1434 | 1435 | /** 1436 | * This object contains basic information about an invoice. 1437 | */ 1438 | export interface TelegramInvoice { 1439 | /** 1440 | * Product name 1441 | */ 1442 | title: string; 1443 | /** 1444 | * Product description 1445 | */ 1446 | description: string; 1447 | /** 1448 | * Unique bot deep-linking parameter that can be used to generate this invoice 1449 | */ 1450 | start_parameter: string; 1451 | /** 1452 | * Three-letter ISO 4217 [currency](https://core.telegram.org/bots/payments#supported-currencies) code 1453 | */ 1454 | currency: string; 1455 | /** 1456 | * Price of the product in the smallest units of the 1457 | * [currency](https://core.telegram.org/bots/payments#supported-currencies) * (integer, not float/double). 1458 | * For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in 1459 | * [currencies.json](https://core.telegram.org/bots/payments/currencies.json_), 1460 | * it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). 1461 | */ 1462 | total_amount: number; 1463 | } 1464 | 1465 | /** 1466 | * This object represents a shipping address. 1467 | */ 1468 | export interface TelegramShippingAddress { 1469 | /** 1470 | * ISO 3166-1 alpha-2 country code 1471 | */ 1472 | country_code: string; 1473 | /** 1474 | * State, if applicable 1475 | */ 1476 | state: string; 1477 | /** 1478 | * City 1479 | */ 1480 | city: string; 1481 | /** 1482 | * First line for the address 1483 | */ 1484 | street_line1: string; 1485 | /** 1486 | * Second line for the address 1487 | */ 1488 | street_line2: string; 1489 | /** 1490 | * Address postal code 1491 | */ 1492 | post_code: string; 1493 | } 1494 | 1495 | /** 1496 | * This object represents information about an order. 1497 | */ 1498 | export interface TelegramOrderInfo { 1499 | /** 1500 | * _Optional._ User name 1501 | */ 1502 | name?: string; 1503 | /** 1504 | * _Optional._ User's phone number 1505 | */ 1506 | phone_number?: string; 1507 | /** 1508 | * _Optional._ User email 1509 | */ 1510 | email?: string; 1511 | /** 1512 | * _Optional._ User shipping address 1513 | */ 1514 | shipping_address?: TelegramShippingAddress; 1515 | } 1516 | 1517 | /** 1518 | * This object represents one shipping option 1519 | */ 1520 | export interface TelegramShippingOption { 1521 | /** 1522 | * Shipping option identifier 1523 | */ 1524 | id: string; 1525 | /** 1526 | * Option title 1527 | */ 1528 | title: string; 1529 | /** 1530 | * List of price portions 1531 | */ 1532 | prices: TelegramLabeledPrice[]; 1533 | } 1534 | 1535 | /** 1536 | * This object contains basic information about a successful payment 1537 | */ 1538 | export interface TelegramSuccessfulPayment { 1539 | /** 1540 | * Three-letter ISO 4217 [currency](https://core.telegram.org/bots/payments#supported-currencies) code 1541 | */ 1542 | currency: string; 1543 | /** 1544 | * Price of the product in the smallest units of the 1545 | * [currency](https://core.telegram.org/bots/payments#supported-currencies) * (integer, not float/double). 1546 | * For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in 1547 | * [currencies.json](https://core.telegram.org/bots/payments/currencies.json_), 1548 | * it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). 1549 | */ 1550 | total_amount: number; 1551 | /** 1552 | * Bot specified invoice payload 1553 | */ 1554 | invoice_payload: string; 1555 | /** 1556 | * _Optional._ Identifier of the shipping option chosen by the user 1557 | */ 1558 | shipping_option_id?: string; 1559 | /** 1560 | * _Optional._ Order info provided by the user 1561 | */ 1562 | order_info?: TelegramOrderInfo; 1563 | /** 1564 | * payment identifier 1565 | */ 1566 | telegram_payment_charge_id: string; 1567 | /** 1568 | * Provider payment identifier 1569 | */ 1570 | provider_payment_charge_id: string; 1571 | } 1572 | 1573 | /** 1574 | * This object contains information about an incoming pre-checkout query 1575 | */ 1576 | export interface TelegramPreCheckoutQuery { 1577 | /** 1578 | * Unique query identifier 1579 | */ 1580 | id: string; 1581 | /** 1582 | * User who sent the query 1583 | */ 1584 | from: TelegramUser; 1585 | /** 1586 | * Three-letter ISO 4217 [currency](https://core.telegram.org/bots/payments#supported-currencies) code 1587 | */ 1588 | currency: string; 1589 | /** 1590 | * Price of the product in the smallest units of the 1591 | * [currency](https://core.telegram.org/bots/payments#supported-currencies) * (integer, not float/double). 1592 | * For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in 1593 | * [currencies.json](https://core.telegram.org/bots/payments/currencies.json_), 1594 | * it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). 1595 | */ 1596 | total_amount: number; 1597 | /** 1598 | * Bot specified invoice payload 1599 | */ 1600 | invoice_payload: string; 1601 | /** 1602 | * _Optional._ Identifier of the shipping option chosen by the user 1603 | */ 1604 | shipping_option_id?: string; 1605 | /** 1606 | * _Optional._ Order info provided by the user 1607 | */ 1608 | order_info?: TelegramOrderInfo; 1609 | } 1610 | 1611 | /************************************* 1612 | * 1613 | * T E L E G R A M P A S S P O R T 1614 | * 1615 | *************************************/ 1616 | 1617 | /** 1618 | * Containts information about Passport data shared with the bot by the user 1619 | */ 1620 | export interface TelegramPassportData { 1621 | /** 1622 | * Array with information about documents and other Passport elements that was shared with the bot 1623 | */ 1624 | data: TelegramEncryptedPassportElement[]; 1625 | /** 1626 | * Encrypted credentials required to decrypt the data 1627 | */ 1628 | credentials: TelegramEncryptedCredentials; 1629 | } 1630 | 1631 | /** 1632 | * This object represents a file uploaded to Passport. 1633 | * Currently all Passport files are in JPEG format when decrypted and don't exceed 10MB. 1634 | */ 1635 | export interface TelegramPassportFile { 1636 | /** 1637 | * Unique identifier for this file 1638 | */ 1639 | file_id: string; 1640 | /** 1641 | * File size 1642 | */ 1643 | file_size: number; 1644 | /** 1645 | * Unix time when the file was uploaded 1646 | */ 1647 | file_date: number; 1648 | } 1649 | /** 1650 | * Contains information about documents or other Passport elements shared with the bot by the user. 1651 | */ 1652 | export interface TelegramEncryptedPassportElement { 1653 | /** 1654 | * Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, 1655 | * “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, 1656 | * “phone_number”, “email”. 1657 | */ 1658 | type: 1659 | | 'personal_details' 1660 | | 'passport' 1661 | | 'driver_license' 1662 | | 'identity_card' 1663 | | 'internal_passport' 1664 | | 'address' 1665 | | 'utility_bill' 1666 | | 'bank_statement' 1667 | | 'rental_agreement' 1668 | | 'passport_registration' 1669 | | 'temporary_registration' 1670 | | 'phone_number' 1671 | | 'email'; 1672 | /** 1673 | * _Optional._ Base64-encoded encrypted Passport element data provided by the user, available for “personal_details”, 1674 | * “passport”, “driver_license”, “identity_card”, “internal_passport” and “address” types. 1675 | * Can be decrypted and verified using the accompanying [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1676 | */ 1677 | data?: string; 1678 | /** 1679 | * _Optional._ User's verified phone number, available only for “phone_number” type 1680 | */ 1681 | phone_number?: string; 1682 | /** 1683 | * _Optional._ User's verified email address, available only for “email” type 1684 | */ 1685 | email?: string; 1686 | /** 1687 | * _Optional._ Array of encrypted files with documents provided by the user, available for “utility_bill”, 1688 | * “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” 1689 | * types. Files can be decrypted and verified using the accompanying 1690 | * [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1691 | */ 1692 | files?: TelegramPassportFile[]; 1693 | /** 1694 | * _Optional._ Encrypted file with the front side of the document, provided by the user. Available for “passport”, 1695 | * “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the 1696 | * accompanying [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1697 | */ 1698 | front_side?: TelegramPassportFile; 1699 | /** 1700 | * _Optional._ Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” 1701 | * and “identity_card”. The file can be decrypted and verified using the accompanying 1702 | * [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1703 | */ 1704 | reverse_side?: TelegramPassportFile; 1705 | /** 1706 | * _Optional._ Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, 1707 | * “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying 1708 | * [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1709 | */ 1710 | selfie?: TelegramPassportFile; 1711 | /** 1712 | * _Optional._ Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, 1713 | * “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, 1714 | * “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified 1715 | * using the accompanying [EncryptedCredentials.](https://core.telegram.org/bots/api#encryptedcredentials) 1716 | */ 1717 | translation?: TelegramPassportFile[]; 1718 | /** 1719 | * Base64-encoded element hash for using in 1720 | * [PassportElementErrorUnspecified](https://core.telegram.org/bots/api#passportelementerrorunspecified) 1721 | */ 1722 | hash: string; 1723 | } 1724 | 1725 | /** 1726 | * Contains data required for decrypting and authenticating 1727 | * [EncryptedPassportElement](https://core.telegram.org/bots/api#encryptedpassportelement). 1728 | * See the [ Passport Documentation](https://core.telegram.org/passport#receiving-information) 1729 | * for a complete description of the data decryption and authentication processes. 1730 | */ 1731 | export interface TelegramEncryptedCredentials { 1732 | /** 1733 | * Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for 1734 | * [EncryptedPassportElement](https://core.telegram.org/bots/api#encryptedpassportelement) decryption and authentication 1735 | */ 1736 | data: string; 1737 | /** 1738 | * Base64-encoded data hash for data authentication 1739 | */ 1740 | hash: string; 1741 | /** 1742 | * Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption 1743 | */ 1744 | secret: string; 1745 | } 1746 | 1747 | /************************************* 1748 | * 1749 | * T E L E G R A M G A M E S 1750 | * 1751 | *************************************/ 1752 | 1753 | /** 1754 | * This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. 1755 | */ 1756 | export interface TelegramGame { 1757 | /** 1758 | * Title of the game 1759 | */ 1760 | title: string; 1761 | /** 1762 | * Description of the game 1763 | */ 1764 | description: string; 1765 | /** 1766 | * Photo that will be displayed in the game message in chats 1767 | */ 1768 | photo: TelegramPhotoSize[]; 1769 | /** 1770 | * _Optional._ Brief description of the game or high scores included in the game message. Can be automatically 1771 | * edited to include current high scores for the game when the bot calls 1772 | * [setGameScore](https://core.telegram.org/bots/api#setgamescore), or manually edited using 1773 | * [editMessageText](https://core.telegram.org/bots/api#editmessagetext). 0-4096 characters. 1774 | */ 1775 | text?: string; 1776 | /** 1777 | * _Optional._ Special entities that appear in text, such as usernames, URLs, bot commands, etc. 1778 | */ 1779 | text_entities?: TelegramMessageEntity[]; 1780 | /** 1781 | * _Optional._ Animation that will be displayed in the game message in chats. Upload via [BotFather](https://t.me/botfather) 1782 | */ 1783 | animation?: TelegramAnimation; 1784 | } 1785 | 1786 | /** 1787 | * A placeholder, currently holds no information. Use BotFather to set up your game. 1788 | */ 1789 | // tslint:disable-next-line 1790 | export interface TelegramCallbackGame {} 1791 | 1792 | /** 1793 | * This object represents one row of the high scores table for a game. 1794 | */ 1795 | export interface TelegramGameHighScore { 1796 | /** 1797 | * Position in high score table for the game 1798 | */ 1799 | position: number; 1800 | /** 1801 | * User who set the high score 1802 | */ 1803 | user: TelegramUser; 1804 | /** 1805 | * What the score was 1806 | */ 1807 | score: number; 1808 | } 1809 | 1810 | /******************************************** 1811 | * 1812 | * T E L E G R A M R E T U R N T Y P E S 1813 | * 1814 | ********************************************/ 1815 | 1816 | /** 1817 | * Response object sent from . If "ok" is true, the API callout was successful, 1818 | * otherwise the error_code, and description will have information about what happened 1819 | */ 1820 | export interface TelegramResponse { 1821 | ok: boolean; 1822 | result?: T; 1823 | error_code?: number; 1824 | description?: string; 1825 | } 1826 | 1827 | export class TelegramException extends BadRequestException { 1828 | constructor(message?: string | object | any, error?: string) { 1829 | super(message, error); 1830 | } 1831 | } 1832 | 1833 | /** 1834 | * 1835 | * T E L E G R A M P A R A M E T E R S 1836 | * 1837 | */ 1838 | 1839 | interface TelegramChatId { 1840 | /** 1841 | * Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`) 1842 | */ 1843 | chat_id: number | string; 1844 | } 1845 | 1846 | /** 1847 | * @see https://core.telegram.org/bots/api#getupdates 1848 | */ 1849 | export interface GetUpdatesParams { 1850 | /** 1851 | * Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of 1852 | * previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An 1853 | * update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The 1854 | * negative offset can be specified to retrieve updates starting from -offset update from the end of the updates 1855 | * queue. All previous updates will forgotten. 1856 | */ 1857 | offset?: number; 1858 | 1859 | /** 1860 | * Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100. 1861 | */ 1862 | limit?: number; 1863 | 1864 | /** 1865 | * Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling 1866 | * should be used for testing purposes only. 1867 | */ 1868 | timeout?: number; 1869 | 1870 | /** 1871 | * A JSON-serialized list of the update types you want your bot to receive. For example, specify 1872 | * [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a 1873 | * complete list of available update types. Specify an empty list to receive all update types except chat_member 1874 | * (default). If not specified, the previous setting will be used. 1875 | * 1876 | * Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted 1877 | * updates may be received for a short period of time. 1878 | */ 1879 | allowed_updates?: string[]; 1880 | } 1881 | 1882 | export interface TelegramSendMessageParams extends TelegramChatId { 1883 | /** 1884 | * Text of the message to be sent 1885 | */ 1886 | text: string; 1887 | /** 1888 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 1889 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 1890 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 1891 | */ 1892 | parse_mode?: 'markdown' | 'html'; 1893 | /** 1894 | * Disables link previews for links in this message 1895 | */ 1896 | disable_web_page_preview?: boolean; 1897 | /** 1898 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 1899 | */ 1900 | disable_notification?: boolean; 1901 | /** 1902 | * If the message is a reply, ID of the original message 1903 | */ 1904 | reply_to_message_id?: number; 1905 | /** 1906 | * Additional interface options. A JSON-serialized object for an 1907 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 1908 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 1909 | * , instructions to remove reply keyboard or to force a reply from the user. 1910 | */ 1911 | reply_markup?: 1912 | | TelegramInlineKeyboardMarkup 1913 | | TelegramReplyKeyboardMarkup 1914 | | TelegramReplyKeyboardRemove 1915 | | TelegramForceReply; 1916 | } 1917 | 1918 | export interface TelegramForwardMessageParams extends TelegramChatId { 1919 | /** 1920 | * Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) 1921 | */ 1922 | from_chat_id: number | string; 1923 | /** 1924 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 1925 | */ 1926 | disable_notification?: boolean; 1927 | /** 1928 | * Message identifier in the chat specified in from_chat_id 1929 | */ 1930 | message_id: number; 1931 | } 1932 | 1933 | export interface TelegramSendPhotoParams extends TelegramChatId { 1934 | /** 1935 | * Photo to send. Pass a file_id as String to send a photo that exists on the servers 1936 | * (recommended), pass an HTTP URL as a String for to get a photo from the Internet, or upload a new photo using 1937 | * multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1938 | */ 1939 | photo: Buffer | string; 1940 | /** 1941 | * Photo caption (may also be used when resending photos by file_id), 0-1024 characters 1942 | */ 1943 | caption?: string; 1944 | /** 1945 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 1946 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 1947 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 1948 | */ 1949 | parse_mode?: string; 1950 | /** 1951 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 1952 | */ 1953 | disable_notification?: boolean; 1954 | /** 1955 | * If the message is a reply, ID of the original message 1956 | */ 1957 | reply_to_message_id?: number; 1958 | /** 1959 | * Additional interface options. A JSON-serialized object for an 1960 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 1961 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 1962 | * , instructions to remove reply keyboard or to force a reply from the user. 1963 | */ 1964 | reply_markup?: 1965 | | TelegramInlineKeyboardMarkup 1966 | | TelegramReplyKeyboardMarkup 1967 | | TelegramReplyKeyboardRemove 1968 | | TelegramForceReply; 1969 | } 1970 | 1971 | export interface TelegramSendAudioParams extends TelegramChatId { 1972 | /** 1973 | * Audio file to send. Pass a file_id as String to send an audio file that exists on the servers (recommended), 1974 | * pass an HTTP URL as a String for to get an audio file from the Internet, 1975 | * or upload a new one using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 1976 | */ 1977 | audio: Buffer | string; 1978 | /** 1979 | * Audio caption, 0-1024 characters 1980 | */ 1981 | caption?: string; 1982 | /** 1983 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 1984 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 1985 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 1986 | */ 1987 | parse_mode?: string; 1988 | /** 1989 | * Duration of the audio in seconds 1990 | */ 1991 | duration?: number; 1992 | /** 1993 | * Performer 1994 | */ 1995 | performer?: string; 1996 | /** 1997 | * Track name 1998 | */ 1999 | title?: string; 2000 | /** 2001 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2002 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2003 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2004 | * “attach://” if the thumbnail was uploaded using 2005 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2006 | */ 2007 | thumb?: Buffer | string; 2008 | /** 2009 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2010 | */ 2011 | disable_notification?: boolean; 2012 | /** 2013 | * If the message is a reply, ID of the original message 2014 | */ 2015 | reply_to_message_id?: number; 2016 | /** 2017 | * Additional interface options. A JSON-serialized object for an 2018 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2019 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2020 | * , instructions to remove reply keyboard or to force a reply from the user. 2021 | */ 2022 | reply_markup?: 2023 | | TelegramInlineKeyboardMarkup 2024 | | TelegramReplyKeyboardMarkup 2025 | | TelegramReplyKeyboardRemove 2026 | | TelegramForceReply; 2027 | } 2028 | 2029 | export interface TelegramSendDocumentParams extends TelegramChatId { 2030 | /** 2031 | * File to send. Pass a file_id as String to send a file that exists on the servers (recommended), 2032 | * pass an HTTP URL as a String for to get a file from the Internet, 2033 | * or upload a new one using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2034 | */ 2035 | document: Buffer | string; 2036 | /** 2037 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2038 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2039 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2040 | * “attach://” if the thumbnail was uploaded using 2041 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2042 | */ 2043 | thumb?: Buffer | string; 2044 | /** 2045 | * Document caption (may also be used when resending documents by file_id), 0-1024 characters 2046 | */ 2047 | caption?: string; 2048 | /** 2049 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 2050 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 2051 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2052 | */ 2053 | parse_mode?: string; 2054 | /** 2055 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2056 | */ 2057 | disable_notification?: boolean; 2058 | /** 2059 | * If the message is a reply, ID of the original message 2060 | */ 2061 | reply_to_message_id?: number; 2062 | /** 2063 | * Additional interface options. A JSON-serialized object for an 2064 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2065 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2066 | * , instructions to remove reply keyboard or to force a reply from the user. 2067 | */ 2068 | reply_markup?: 2069 | | TelegramInlineKeyboardMarkup 2070 | | TelegramReplyKeyboardMarkup 2071 | | TelegramReplyKeyboardRemove 2072 | | TelegramForceReply; 2073 | } 2074 | 2075 | export interface TelegramSendVideoParams extends TelegramChatId { 2076 | /** 2077 | * Video to send. Pass a file_id as String to send a video that exists on the servers (recommended), 2078 | * pass an HTTP URL as a String for to get a video from the Internet, 2079 | * or upload a new video using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2080 | */ 2081 | video: Buffer | string; 2082 | /** 2083 | * Duration of sent video in seconds 2084 | */ 2085 | duration?: number; 2086 | /** 2087 | * Video width 2088 | */ 2089 | width?: number; 2090 | /** 2091 | * Video height 2092 | */ 2093 | height?: number; 2094 | /** 2095 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2096 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2097 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2098 | * “attach://” if the thumbnail was uploaded using 2099 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2100 | */ 2101 | thumb?: Buffer | string; 2102 | /** 2103 | * Video caption (may also be used when resending videos by file_id), 0-1024 characters 2104 | */ 2105 | caption?: string; 2106 | /** 2107 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 2108 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 2109 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2110 | */ 2111 | parse_mode?: string; 2112 | /** 2113 | * Pass True, if the uploaded video is suitable for streaming 2114 | */ 2115 | supports_streaming?: boolean; 2116 | /** 2117 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2118 | */ 2119 | disable_notification?: boolean; 2120 | /** 2121 | * If the message is a reply, ID of the original message 2122 | */ 2123 | reply_to_message_id?: number; 2124 | /** 2125 | * Additional interface options. A JSON-serialized object for an 2126 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2127 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2128 | * , instructions to remove reply keyboard or to force a reply from the user. 2129 | */ 2130 | reply_markup?: 2131 | | TelegramInlineKeyboardMarkup 2132 | | TelegramReplyKeyboardMarkup 2133 | | TelegramReplyKeyboardRemove 2134 | | TelegramForceReply; 2135 | } 2136 | 2137 | export interface TelegramSendVideoNoteParams extends TelegramChatId { 2138 | /** 2139 | * Video note to send. Pass a file_id as String to send a video note that exists on the servers (recommended), 2140 | * pass an HTTP URL as a String for to get a video from the Internet, 2141 | * or upload a new video using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2142 | */ 2143 | video_note: Buffer | string; 2144 | /** 2145 | * Duration of sent video in seconds 2146 | */ 2147 | duration?: number; 2148 | /** 2149 | * Video width 2150 | */ 2151 | width?: number; 2152 | /** 2153 | * Video height 2154 | */ 2155 | height?: number; 2156 | /** 2157 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2158 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2159 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2160 | * “attach://” if the thumbnail was uploaded using 2161 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2162 | */ 2163 | thumb?: Buffer | string; 2164 | /** 2165 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2166 | */ 2167 | disable_notification?: boolean; 2168 | /** 2169 | * If the message is a reply, ID of the original message 2170 | */ 2171 | reply_to_message_id?: number; 2172 | /** 2173 | * Additional interface options. A JSON-serialized object for an 2174 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2175 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2176 | * , instructions to remove reply keyboard or to force a reply from the user. 2177 | */ 2178 | reply_markup?: 2179 | | TelegramInlineKeyboardMarkup 2180 | | TelegramReplyKeyboardMarkup 2181 | | TelegramReplyKeyboardRemove 2182 | | TelegramForceReply; 2183 | } 2184 | 2185 | export interface TelegramSendAnimationParams extends TelegramChatId { 2186 | /** 2187 | * Animation to send. Pass a file_id as String to send a animation that exists on the servers (recommended), 2188 | * pass an HTTP URL as a String for to get a animation from the Internet, 2189 | * or upload a new animation using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2190 | */ 2191 | animation: Buffer | string; 2192 | /** 2193 | * Duration of sent video in seconds 2194 | */ 2195 | duration?: number; 2196 | /** 2197 | * Video width 2198 | */ 2199 | width?: number; 2200 | /** 2201 | * Video height 2202 | */ 2203 | height?: number; 2204 | /** 2205 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2206 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2207 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2208 | * “attach://” if the thumbnail was uploaded using 2209 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2210 | */ 2211 | thumb?: Buffer | string; 2212 | /** 2213 | * Video caption (may also be used when resending videos by file_id), 0-1024 characters 2214 | */ 2215 | caption?: string; 2216 | /** 2217 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 2218 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 2219 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2220 | */ 2221 | parse_mode?: string; 2222 | /** 2223 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2224 | */ 2225 | disable_notification?: boolean; 2226 | /** 2227 | * If the message is a reply, ID of the original message 2228 | */ 2229 | reply_to_message_id?: number; 2230 | /** 2231 | * Additional interface options. A JSON-serialized object for an 2232 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2233 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2234 | * , instructions to remove reply keyboard or to force a reply from the user. 2235 | */ 2236 | reply_markup?: 2237 | | TelegramInlineKeyboardMarkup 2238 | | TelegramReplyKeyboardMarkup 2239 | | TelegramReplyKeyboardRemove 2240 | | TelegramForceReply; 2241 | } 2242 | 2243 | export interface TelegramSendVoiceParams extends TelegramChatId { 2244 | /** 2245 | * Audio file to send. Pass a file_id as String to send a file that exists on the servers (recommended), 2246 | * pass an HTTP URL as a String for to get a file from the Internet, 2247 | * or upload a new file using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2248 | */ 2249 | voice: Buffer | string; 2250 | /** 2251 | * Duration of sent video in seconds 2252 | */ 2253 | duration?: number; 2254 | /** 2255 | * Video width 2256 | */ 2257 | width?: number; 2258 | /** 2259 | * Video height 2260 | */ 2261 | height?: number; 2262 | /** 2263 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2264 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2265 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2266 | * “attach://” if the thumbnail was uploaded using 2267 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2268 | */ 2269 | thumb?: Buffer | string; 2270 | /** 2271 | * Video caption (may also be used when resending videos by file_id), 0-1024 characters 2272 | */ 2273 | caption?: string; 2274 | /** 2275 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 2276 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 2277 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2278 | */ 2279 | parse_mode?: string; 2280 | /** 2281 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2282 | */ 2283 | disable_notification?: boolean; 2284 | /** 2285 | * If the message is a reply, ID of the original message 2286 | */ 2287 | reply_to_message_id?: number; 2288 | /** 2289 | * Additional interface options. A JSON-serialized object for an 2290 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2291 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2292 | * , instructions to remove reply keyboard or to force a reply from the user. 2293 | */ 2294 | reply_markup?: 2295 | | TelegramInlineKeyboardMarkup 2296 | | TelegramReplyKeyboardMarkup 2297 | | TelegramReplyKeyboardRemove 2298 | | TelegramForceReply; 2299 | } 2300 | 2301 | export interface TelegramSendVoiceParams extends TelegramChatId { 2302 | /** 2303 | * Video note to send. Pass a file_id as String to send a video note that exists on the servers (recommended), 2304 | * pass an HTTP URL as a String for to get a file from the Internet, 2305 | * or upload a new video using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2306 | */ 2307 | video_note: Buffer | string; 2308 | /** 2309 | * Duration of sent video in seconds 2310 | */ 2311 | duration?: number; 2312 | /** 2313 | * Video width and height, i.e. diameter of the video message 2314 | */ 2315 | length?: number; 2316 | /** 2317 | * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in 2318 | * JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. Ignored if the file is not 2319 | * uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass 2320 | * “attach://” if the thumbnail was uploaded using 2321 | * multipart/form-data under . [More info on Sending Files »](https://)core.telegram.org/bots/api#sending-files) 2322 | */ 2323 | thumb?: Buffer | string; 2324 | /** 2325 | * Send [Markdown](https://core.telegram.org/bots/api#markdown-style) or 2326 | * [HTML](https://core.telegram.org/bots/api#html-style), if you want apps to show 2327 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2328 | */ 2329 | parse_mode?: string; 2330 | /** 2331 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2332 | */ 2333 | disable_notification?: boolean; 2334 | /** 2335 | * If the message is a reply, ID of the original message 2336 | */ 2337 | reply_to_message_id?: number; 2338 | /** 2339 | * Additional interface options. A JSON-serialized object for an 2340 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2341 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2342 | * , instructions to remove reply keyboard or to force a reply from the user. 2343 | */ 2344 | reply_markup?: 2345 | | TelegramInlineKeyboardMarkup 2346 | | TelegramReplyKeyboardMarkup 2347 | | TelegramReplyKeyboardRemove 2348 | | TelegramForceReply; 2349 | } 2350 | 2351 | export interface TelegramSendMediaGroupParams extends TelegramChatId { 2352 | /** 2353 | * A JSON-serialized array describing photos and videos to be sent, must include 2–10 items 2354 | */ 2355 | media: TelegramInputMediaPhoto[] | TelegramInputMediaVideo[]; 2356 | /** 2357 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2358 | */ 2359 | disable_notification?: boolean; 2360 | /** 2361 | * If the messages are a reply, ID of the original message 2362 | */ 2363 | reply_to_message_id?: number; 2364 | } 2365 | 2366 | export interface TelegramSendLocationParams extends TelegramChatId { 2367 | /** 2368 | * Latitude of the location 2369 | */ 2370 | latitude: number; 2371 | /** 2372 | * Longitude of the location 2373 | */ 2374 | longitude: number; 2375 | live_period?: number; 2376 | /** 2377 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2378 | */ 2379 | disable_notification?: boolean; 2380 | /** 2381 | * If the messages are a reply, ID of the original message 2382 | */ 2383 | reply_to_message_id?: number; 2384 | /** 2385 | * Additional interface options. A JSON-serialized object for an 2386 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2387 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2388 | * , instructions to remove reply keyboard or to force a reply from the user. 2389 | */ 2390 | reply_markup?: 2391 | | TelegramInlineKeyboardMarkup 2392 | | TelegramReplyKeyboardMarkup 2393 | | TelegramReplyKeyboardRemove 2394 | | TelegramForceReply; 2395 | } 2396 | 2397 | export interface TelegramEditMessageLiveLocationParams { 2398 | /** 2399 | * Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target 2400 | * channel (in the format `@channelusername`) 2401 | */ 2402 | chat_id?: number | string; 2403 | /** 2404 | * Required if inline_message_id is not specified. Identifier of the message to edit 2405 | */ 2406 | message_id?: number; 2407 | /** 2408 | * Required if chat_id and message_id are not specified. Identifier of the inline message 2409 | */ 2410 | inline_message_id?: string; 2411 | /** 2412 | * Latitude of new location 2413 | */ 2414 | latitude: number; 2415 | /** 2416 | * Longitude of new location 2417 | */ 2418 | longitude: number; 2419 | /** 2420 | * A JSON-serialized object for a new [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2421 | */ 2422 | reply_markup?: TelegramInlineKeyboardMarkup; 2423 | } 2424 | 2425 | export interface TelegramStopMessageLiveLocationParams { 2426 | /** 2427 | * Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target 2428 | * channel (in the format `@channelusername`) 2429 | */ 2430 | chat_id?: number | string; 2431 | /** 2432 | * Required if inline_message_id is not specified. Identifier of the message to edit 2433 | */ 2434 | message_id?: number; 2435 | /** 2436 | * Required if chat_id and message_id are not specified. Identifier of the inline message 2437 | */ 2438 | inline_message_id?: string; 2439 | /** 2440 | * A JSON-serialized object for a new [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2441 | */ 2442 | reply_markup?: TelegramInlineKeyboardMarkup; 2443 | } 2444 | 2445 | export interface TelegramSendVenueParams extends TelegramChatId { 2446 | /** 2447 | * Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) 2448 | */ 2449 | chat_id: number | string; 2450 | /** 2451 | * Latitude of the venue 2452 | */ 2453 | latitude: number; 2454 | /** 2455 | * Longitude of the venue 2456 | */ 2457 | longitude: number; 2458 | /** 2459 | * Name of the venue 2460 | */ 2461 | title: string; 2462 | /** 2463 | * Address of the venue 2464 | */ 2465 | address: string; 2466 | /** 2467 | * Foursquare identifier of the venue 2468 | */ 2469 | foursquare_id?: string; 2470 | /** 2471 | * Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) 2472 | */ 2473 | foursquare_type?: string; 2474 | /** 2475 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2476 | */ 2477 | disable_notification?: boolean; 2478 | /** 2479 | * If the messages are a reply, ID of the original message 2480 | */ 2481 | reply_to_message_id?: number; 2482 | /** 2483 | * Additional interface options. A JSON-serialized object for an 2484 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2485 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2486 | * , instructions to remove reply keyboard or to force a reply from the user. 2487 | */ 2488 | reply_markup?: 2489 | | TelegramInlineKeyboardMarkup 2490 | | TelegramReplyKeyboardMarkup 2491 | | TelegramReplyKeyboardRemove 2492 | | TelegramForceReply; 2493 | } 2494 | 2495 | export interface TelegramSendContactParams extends TelegramChatId { 2496 | /** 2497 | * Contact's phone number 2498 | */ 2499 | phone_number: string; 2500 | /** 2501 | * Contact's first name 2502 | */ 2503 | first_name: string; 2504 | /** 2505 | * Contact's last name 2506 | */ 2507 | last_name?: string; 2508 | /** 2509 | * Additional data about the contact in the form of a [vCard](https://en.wikipedia.org/wiki/VCard), 0-2048 bytes 2510 | */ 2511 | vcard?: string; 2512 | /** 2513 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2514 | */ 2515 | disable_notification?: boolean; 2516 | /** 2517 | * If the messages are a reply, ID of the original message 2518 | */ 2519 | reply_to_message_id?: number; 2520 | /** 2521 | * Additional interface options. A JSON-serialized object for an 2522 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2523 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2524 | * , instructions to remove reply keyboard or to force a reply from the user. 2525 | */ 2526 | reply_markup?: 2527 | | TelegramInlineKeyboardMarkup 2528 | | TelegramReplyKeyboardMarkup 2529 | | TelegramReplyKeyboardRemove 2530 | | TelegramForceReply; 2531 | } 2532 | 2533 | export interface TelegramSendPollParams extends TelegramChatId { 2534 | /** 2535 | * Poll question, 1-255 characters 2536 | */ 2537 | question: string; 2538 | /** 2539 | * List of answer options, 2-10 strings 1-100 characters each 2540 | */ 2541 | options: string[]; 2542 | /** 2543 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2544 | */ 2545 | disable_notification?: boolean; 2546 | /** 2547 | * If the messages are a reply, ID of the original message 2548 | */ 2549 | reply_to_message_id?: number; 2550 | /** 2551 | * Additional interface options. A JSON-serialized object for an 2552 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2553 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2554 | * , instructions to remove reply keyboard or to force a reply from the user. 2555 | */ 2556 | reply_markup?: 2557 | | TelegramInlineKeyboardMarkup 2558 | | TelegramReplyKeyboardMarkup 2559 | | TelegramReplyKeyboardRemove 2560 | | TelegramForceReply; 2561 | } 2562 | 2563 | export interface TelegramSendChatActionParams extends TelegramChatId { 2564 | /** 2565 | * Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for 2566 | * [text messages](https://core.telegram.org/bots/api#sendmessage), 2567 | * upload_photo for [photos](https://core.telegram.org/bots/api#sendphoto), 2568 | * record_video or upload_video for [videos](https://core.telegram.org/bots/api#sendvideo), 2569 | * record_audio or upload_audio for [audio files](https://core.telegram.org/bots/api#sendaudio), 2570 | * upload_document for [general files](https://core.telegram.org/bots/api#senddocument), 2571 | * find_location for [location data](https://core.telegram.org/bots/api#sendlocation), 2572 | * record_video_note or upload_video_note for [video notes](https://core.telegram.org/bots/api#sendvideonote). 2573 | */ 2574 | action: string; 2575 | } 2576 | 2577 | export interface TelegramGetUserProfilePhotosParams { 2578 | /** 2579 | * Unique identifier of the target user 2580 | */ 2581 | user_id: number; 2582 | /** 2583 | * Sequential number of the first photo to be returned. By default, all photos are returned. 2584 | */ 2585 | offset?: number; 2586 | /** 2587 | * Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. 2588 | */ 2589 | limit?: number; 2590 | } 2591 | 2592 | export interface TelegramGetFileParams { 2593 | /** 2594 | * File identifier to get info about 2595 | */ 2596 | file_id: string; 2597 | } 2598 | 2599 | export interface TelegramKickChatMemberParams 2600 | extends TelegramUnbanChatMemberParams { 2601 | /** 2602 | * Date when the user will be unbanned, unix time. If user is banned for more than 366 days or 2603 | * less than 30 seconds from the current time they are considered to be banned forever 2604 | */ 2605 | until_date?: number; 2606 | } 2607 | 2608 | export interface TelegramUnbanChatMemberParams extends TelegramChatId { 2609 | /** 2610 | * Unique identifier of the target user 2611 | */ 2612 | user_id: number; 2613 | } 2614 | 2615 | export interface TelegramRestrictChatMemberParams 2616 | extends TelegramKickChatMemberParams { 2617 | /** 2618 | * Pass True, if the user can send text messages, contacts, locations and venues 2619 | */ 2620 | can_send_messages?: boolean; 2621 | /** 2622 | * Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages 2623 | */ 2624 | can_send_media_messages?: boolean; 2625 | /** 2626 | * Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages 2627 | */ 2628 | can_send_other_messages?: boolean; 2629 | /** 2630 | * Pass True, if the user may add web page previews to their messages, implies can_send_media_messages 2631 | */ 2632 | can_add_web_page_previews?: boolean; 2633 | } 2634 | 2635 | export interface TelegramPromoteChatMemberParams 2636 | extends TelegramUnbanChatMemberParams { 2637 | /** 2638 | * Pass True, if the administrator can change chat title, photo and other settings 2639 | */ 2640 | can_change_info?: boolean; 2641 | /** 2642 | * Pass True, if the administrator can create channel posts, channels only 2643 | */ 2644 | can_post_messages?: boolean; 2645 | /** 2646 | * Pass True, if the administrator can edit messages of other users and can pin messages, channels only 2647 | */ 2648 | can_delete_message?: boolean; 2649 | /** 2650 | * Pass True, if the administrator can delete messages of other users 2651 | */ 2652 | can_edit_messages?: boolean; 2653 | /** 2654 | * Pass True, if the administrator can invite new users to the chat 2655 | */ 2656 | can_invite_users?: boolean; 2657 | /** 2658 | * Pass True, if the administrator can restrict, ban or unban chat members 2659 | */ 2660 | can_restrict_members?: boolean; 2661 | /** 2662 | * Pass True, if the administrator can pin messages, supergroups only 2663 | */ 2664 | can_pin_messages?: boolean; 2665 | /** 2666 | * Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators 2667 | * that he has promoted, directly or indirectly (promoted by administrators that were appointed by him) 2668 | */ 2669 | can_promote_members?: boolean; 2670 | } 2671 | 2672 | export interface TelegramExportChatInviteLinkParams extends TelegramChatId {} 2673 | 2674 | export interface TelegramSetChatPhotoParams extends TelegramChatId { 2675 | /** 2676 | * New chat photo, uploaded using multipart/form-data 2677 | */ 2678 | photo: Buffer; 2679 | } 2680 | 2681 | export interface TelegramDeleteChatPhotoParams extends TelegramChatId {} 2682 | 2683 | export interface TelegramSetChatTitleParams extends TelegramChatId { 2684 | /*** 2685 | * New chat title, 1-255 characters 2686 | */ 2687 | title: string; 2688 | } 2689 | 2690 | export interface TelegramSetChatDescriptionParams extends TelegramChatId { 2691 | /** 2692 | * New chat description, 0-255 characters 2693 | */ 2694 | description?: string; 2695 | } 2696 | 2697 | export interface TelegramPinChatMessageParams extends TelegramChatId { 2698 | /** 2699 | * Identifier of a message to pin 2700 | */ 2701 | message_id: number; 2702 | /** 2703 | * Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. 2704 | * Notifications are always disabled in channels. 2705 | */ 2706 | disable_notifications?: boolean; 2707 | } 2708 | 2709 | export interface TelegramUnpinChatMessageParams extends TelegramChatId { 2710 | /** 2711 | * Identifier of a message to pin 2712 | */ 2713 | message_id: number; 2714 | } 2715 | 2716 | export interface TelegramLeaveChatParams extends TelegramChatId {} 2717 | 2718 | export interface TelegramGetChatParams extends TelegramChatId {} 2719 | 2720 | export interface TelegramGetChatAdministratorsParams extends TelegramChatId {} 2721 | 2722 | export interface TelegramGetChatMembersCountParams extends TelegramChatId {} 2723 | 2724 | export interface TelegramGetChatMemberParams extends TelegramChatId { 2725 | /** 2726 | * Unique identifier of the target user 2727 | */ 2728 | user_id: number; 2729 | } 2730 | 2731 | export interface TelegramSetChatStickerSetParams extends TelegramChatId { 2732 | /** 2733 | * Name of the sticker set to be set as the group sticker set 2734 | */ 2735 | sticker_set_name: string; 2736 | } 2737 | 2738 | export interface TelegramChatDeleteStickerSetParams extends TelegramChatId {} 2739 | 2740 | export interface TelegramAnswerCallbackQueryParams { 2741 | /** 2742 | * Unique identifier for the query to be answered 2743 | */ 2744 | callback_query_id: string; 2745 | /** 2746 | * Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters 2747 | */ 2748 | text?: string; 2749 | /** 2750 | * If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. 2751 | */ 2752 | show_alert?: boolean; 2753 | /** 2754 | * URL that will be opened by the user's client. If you have created a [Game](https://core.telegram.org/bots/api#game) and accepted 2755 | * the conditions via [@Botfather](https://t.me/botfather), 2756 | * specify the URL that opens your game – note that this will only work if the query comes from a 2757 | * [callback_game](https://core.telegram.org/bots/api#inlinekeyboardbutton) button. 2758 | * 2759 | * Otherwise, you may use links like `t.me/your_bot?start=XXXX` that open your bot with a parameter. 2760 | */ 2761 | show_url?: string; 2762 | /** 2763 | * The maximum amount of time in seconds that the result of the callback query may be cached client-side. 2764 | * apps will support caching starting in version 3.14. Defaults to 0. 2765 | */ 2766 | cache_time?: number; 2767 | } 2768 | 2769 | interface TelegramEditMessageId { 2770 | /** 2771 | * Required if inline_message_id is not specified. 2772 | * Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) 2773 | */ 2774 | chat_id?: number | string; 2775 | /** 2776 | * Required if inline_message_id is not specified. Identifier of the message to edit 2777 | */ 2778 | message_id?: number; 2779 | /** 2780 | * Required if chat_id and message_id are not specified. Identifier of the inline message 2781 | */ 2782 | inline_message_id?: string; 2783 | } 2784 | 2785 | export interface TelegramEditMessageTextParams extends TelegramEditMessageId { 2786 | /** 2787 | * New text of the message 2788 | */ 2789 | text: string; 2790 | /** 2791 | * Send[Markdown](https://core.telegram.org/bots/api#markdown-style) or [HTML](https://core.telegram.org/bots/api#html-style), 2792 | * if you want apps to show 2793 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2794 | */ 2795 | parse_mode?: string; 2796 | /** 2797 | * Disables link previews for links in this message 2798 | */ 2799 | disable_web_page_view?: boolean; 2800 | /** 2801 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2802 | */ 2803 | reply_markup?: TelegramInlineKeyboardMarkup; 2804 | } 2805 | 2806 | export interface TelegramEditMessageCaptionParams 2807 | extends TelegramEditMessageId { 2808 | /** 2809 | * New caption of the message 2810 | */ 2811 | caption?: string; 2812 | /** 2813 | * Send[Markdown](https://core.telegram.org/bots/api#markdown-style) or [HTML](https://core.telegram.org/bots/api#html-style), 2814 | * if you want apps to show 2815 | * [bold, italic, fixed-width text or inline URLs](https://core.telegram.org/bots/api#formatting-options) in your bot's message. 2816 | */ 2817 | parse_mode?: string; 2818 | /** 2819 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2820 | */ 2821 | reply_markup?: TelegramInlineKeyboardMarkup; 2822 | } 2823 | 2824 | export interface TelegramEditMessageMediaParams extends TelegramEditMessageId { 2825 | /** 2826 | * A JSON-serialized object for a new media content of the message 2827 | */ 2828 | media: TelegramInputMedia; 2829 | /** 2830 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2831 | */ 2832 | reply_markup?: TelegramInlineKeyboardMarkup; 2833 | } 2834 | 2835 | export interface TelegramEditMessageReplyMarkupParams 2836 | extends TelegramEditMessageId { 2837 | /** 2838 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2839 | */ 2840 | reply_markup?: TelegramInlineKeyboardMarkup; 2841 | } 2842 | 2843 | export interface TelegramStopPollParams extends TelegramChatId { 2844 | /** 2845 | * Identifier of the original message with the poll 2846 | */ 2847 | message_id: number; 2848 | /** 2849 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 2850 | */ 2851 | reply_markup?: TelegramInlineKeyboardMarkup; 2852 | } 2853 | 2854 | export interface TelegramDeleteMessageParams extends TelegramChatId { 2855 | /** 2856 | * Identifier of the message to delete 2857 | */ 2858 | message_id: number; 2859 | } 2860 | 2861 | export interface TelegramSendStickerParams extends TelegramChatId { 2862 | /** 2863 | * Sticker to send. Pass a file_id as String to send a file that exists on the servers (recommended), 2864 | * pass an HTTP URL as a String for to get a .webp file from the Internet, or upload a new one 2865 | * using multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2866 | */ 2867 | sticker: Buffer | string; 2868 | /** 2869 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 2870 | */ 2871 | disable_notification?: boolean; 2872 | /** 2873 | * If the messages are a reply, ID of the original message 2874 | */ 2875 | reply_to_message_id?: number; 2876 | /** 2877 | * Additional interface options. A JSON-serialized object for an 2878 | * [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating) 2879 | * , [custom reply keyboard](https://core.telegram.org/bots#keyboards) 2880 | * , instructions to remove reply keyboard or to force a reply from the user. 2881 | */ 2882 | reply_markup?: 2883 | | TelegramInlineKeyboardMarkup 2884 | | TelegramReplyKeyboardMarkup 2885 | | TelegramReplyKeyboardRemove 2886 | | TelegramForceReply; 2887 | } 2888 | 2889 | export interface TelegramGetStickerSetParams { 2890 | /** 2891 | * Name of the sticker set 2892 | */ 2893 | name: string; 2894 | } 2895 | 2896 | export interface TelegramUploadStickerFileParams { 2897 | /** 2898 | * User identifier of sticker file owner 2899 | */ 2900 | user_id: number; 2901 | /** 2902 | * ***Png* image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, 2903 | * and either width or height must be exactly 512px. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2904 | */ 2905 | png_sticker: Buffer; 2906 | } 2907 | 2908 | export interface TelegramCreateNewStickerSetParams { 2909 | /** 2910 | * User identifier of created sticker set owner 2911 | */ 2912 | user_id: number; 2913 | /** 2914 | * Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g., animals). Can contain only english letters, 2915 | * digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in 2916 | * “_by_”. is case insensitive. 1-64 characters. 2917 | */ 2918 | name: string; 2919 | /** 2920 | * Sticker set title, 1-64 characters 2921 | */ 2922 | title: string; 2923 | /** 2924 | * **Png** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and 2925 | * either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the 2926 | * servers, pass an HTTP URL as a String for to get a file from the Internet, or upload a new one using 2927 | * multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2928 | */ 2929 | png_sticker: Buffer | string; 2930 | /** 2931 | * One or more emoji corresponding to the sticker 2932 | */ 2933 | emojis: string; 2934 | /** 2935 | * Pass True, if a set of mask stickers should be created 2936 | */ 2937 | contains_masks?: boolean; 2938 | /** 2939 | * A JSON-serialized object for position where the mask should be placed on faces 2940 | */ 2941 | mask_position?: TelegramMaskPosition; 2942 | } 2943 | 2944 | export interface TelegramAddStickerToSetParams { 2945 | /** 2946 | * User identifier of sticker set owner 2947 | */ 2948 | user_id: number; 2949 | /** 2950 | * Sticker set name 2951 | */ 2952 | name: string; 2953 | /** 2954 | * **Png** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and 2955 | * either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the 2956 | * servers, pass an HTTP URL as a String for to get a file from the Internet, or upload a new one using 2957 | * multipart/form-data. [More info on Sending Files »](https://core.telegram.org/bots/api#sending-files) 2958 | */ 2959 | png_sticker: Buffer | string; 2960 | /** 2961 | * One or more emoji corresponding to the sticker 2962 | */ 2963 | emojis: string; 2964 | /** 2965 | * A JSON-serialized object for position where the mask should be placed on faces 2966 | */ 2967 | mask_position?: TelegramMaskPosition; 2968 | } 2969 | 2970 | export interface TelegramSetStickerPositionInSetParams { 2971 | /** 2972 | * File identifier of the sticker 2973 | */ 2974 | sticker: string; 2975 | /** 2976 | * new sticker position in the set, zero-based 2977 | */ 2978 | position: number; 2979 | } 2980 | 2981 | export interface TelegramDeleteStickerFromSetParams { 2982 | /** 2983 | * File identifier of the sticker 2984 | */ 2985 | sticker: string; 2986 | } 2987 | 2988 | export interface TelegramSendInvoiceParams extends TelegramChatId { 2989 | /** 2990 | * Product name, 1-32 characters 2991 | */ 2992 | title: string; 2993 | /** 2994 | * Product description, 1-255 characters 2995 | */ 2996 | description: string; 2997 | /** 2998 | * Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. 2999 | */ 3000 | payload: string; 3001 | /** 3002 | * Payments provider token, obtained via [Botfather](https://t.me/botfather) 3003 | */ 3004 | provider_token: string; 3005 | /** 3006 | * Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter 3007 | */ 3008 | start_parameter: string; 3009 | /** 3010 | * Three-letter ISO 4217 currency code, see [more on currencies](https://core.telegram.org/bots/payments#supported-currencies) 3011 | */ 3012 | currency: string; 3013 | /** 3014 | * Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) 3015 | */ 3016 | prices: TelegramLabeledPrice[]; 3017 | /** 3018 | * JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of 3019 | * required fields should be provided by the payment provider. 3020 | */ 3021 | provider_data?: string; 3022 | /** 3023 | * URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. 3024 | * People like it better when they see what they are paying for. 3025 | */ 3026 | photo_url?: string; 3027 | /** 3028 | * Photo size 3029 | */ 3030 | photo_size?: number; 3031 | /** 3032 | * Photo width 3033 | */ 3034 | photo_width?: number; 3035 | /** 3036 | * Photo height 3037 | */ 3038 | photo_height?: number; 3039 | /** 3040 | * Pass True, if you require the user's full name to complete the order 3041 | */ 3042 | need_name?: boolean; 3043 | /** 3044 | * Pass True, if you require the user's phone number to complete the order 3045 | */ 3046 | need_phone_number?: boolean; 3047 | /** 3048 | * Pass True, if you require the user's email address to complete the order 3049 | */ 3050 | need_email?: boolean; 3051 | /** 3052 | * Pass True, if you require the user's shipping address to complete the order 3053 | */ 3054 | need_shipping_address?: boolean; 3055 | /** 3056 | * Pass True, if user's phone number should be sent to provider 3057 | */ 3058 | send_phone_number_to_provider?: boolean; 3059 | /** 3060 | * Pass True, if user's email address should be sent to provider 3061 | */ 3062 | send_email_to_provider?: boolean; 3063 | /** 3064 | * Pass True, if the final price depends on the shipping method 3065 | */ 3066 | is_flexible?: boolean; 3067 | /** 3068 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 3069 | */ 3070 | disable_notification?: boolean; 3071 | /** 3072 | * If the message is a reply, ID of the original message 3073 | */ 3074 | reply_to_message_id?: number; 3075 | /** 3076 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 3077 | * If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. 3078 | */ 3079 | reply_markup?: TelegramInlineKeyboardMarkup; 3080 | } 3081 | 3082 | export interface TelegramAnswerShippingQueryParams { 3083 | /** 3084 | * Unique identifier for the query to be answered 3085 | */ 3086 | shipping_query_id: string; 3087 | /** 3088 | * Specify True if delivery to the specified address is possible and False if there are any problems 3089 | * (for example, if delivery to the specified address is not possible) 3090 | */ 3091 | ok: boolean; 3092 | /** 3093 | * Required if ok is True. A JSON-serialized array of available shipping options. 3094 | */ 3095 | shipping_options?: TelegramShippingOption[]; 3096 | /** 3097 | * Required if ok is False. Error message in human readable form that explains why it is impossible to complete 3098 | * the order (e.g. "Sorry, delivery to your desired address is unavailable'). will display this message to the user. 3099 | */ 3100 | error_message?: string; 3101 | } 3102 | 3103 | export interface TelegramAnswerPreCheckoutQueryParams { 3104 | /** 3105 | * Unique identifier for the query to be answered 3106 | */ 3107 | pre_checkout_query_id: string; 3108 | /** 3109 | * Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. 3110 | * Use False if there are any problems. 3111 | */ 3112 | ok: boolean; 3113 | /** 3114 | * Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the 3115 | * checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your 3116 | * payment details. Please choose a different color or garment!"). will display this message to the user. 3117 | */ 3118 | error_message?: string; 3119 | } 3120 | 3121 | export interface TelegramSendGameParams extends TelegramChatId { 3122 | /** 3123 | * Short name of the game, serves as the unique identifier for the game. Set up your games via [Botfather](https://t.me/botfather). 3124 | */ 3125 | game_short_name: string; 3126 | /** 3127 | * Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. 3128 | */ 3129 | disable_notification?: boolean; 3130 | /** 3131 | * If the message is a reply, ID of the original message 3132 | */ 3133 | reply_to_message_id?: number; 3134 | /** 3135 | * A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). 3136 | * If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game. 3137 | */ 3138 | reply_markup?: TelegramInlineKeyboardMarkup; 3139 | } 3140 | 3141 | export interface TelegramSetGameScoreParams { 3142 | /** 3143 | * User identifier 3144 | */ 3145 | user_id: number; 3146 | /** 3147 | * New score, must be non-negative 3148 | */ 3149 | score: number; 3150 | /** 3151 | * Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters 3152 | */ 3153 | force?: boolean; 3154 | /** 3155 | * Pass True, if the game message should not be automatically edited to include the current scoreboard 3156 | */ 3157 | disable_edit_message?: boolean; 3158 | /** 3159 | * Required if inline_message_id is not specified. Unique identifier for the target chat 3160 | */ 3161 | chat_id?: number; 3162 | /** 3163 | * Required if inline_message_id is not specified. Identifier of the sent message 3164 | */ 3165 | message_id?: number; 3166 | /** 3167 | * Required if chat_id and message_id are not specified. Identifier of the inline message 3168 | */ 3169 | inline_message_id?: string; 3170 | } 3171 | 3172 | export interface TelegramGetGameHighScoreParams { 3173 | /** 3174 | * Target user id 3175 | */ 3176 | user_id: number; 3177 | /** 3178 | * Required if inline_message_id is not specified. unique identifier for the target chat 3179 | */ 3180 | chat_id?: number; 3181 | /** 3182 | * Required if inline_message_id is not specified. Identifier of the sent message 3183 | */ 3184 | message_id?: number; 3185 | /** 3186 | * Required if chat_id and message_id are not specified. Identifier of the inline message 3187 | */ 3188 | inline_message_id?: string; 3189 | } 3190 | --------------------------------------------------------------------------------