diff --git a/scripts/generate-interfaces/index.ts b/scripts/generate-interfaces/index.ts index 79bebc38..c3080993 100644 --- a/scripts/generate-interfaces/index.ts +++ b/scripts/generate-interfaces/index.ts @@ -6,7 +6,7 @@ import { stripIndent, stripIndents } from 'common-tags' import * as Types from './types' -// const SCHEMA_URL = `${__dirname}/custom.min.json` +// const SCHEMA_URL = resolve(__dirname, 'custom.min.json') const SCHEMA_URL = 'https://ark0f.github.io/tg-bot-api/custom.min.json' const CURRENCIES_URL = 'https://core.telegram.org/bots/payments/currencies.json' @@ -112,6 +112,10 @@ class InterfaceService { type = `SoftString<${typeName}>` } + if (field.name === 'parse_mode') { + type = 'PossibleParseMode' + } + // INFO: any [TelegramInputFile] must be replaced with [MediaInput] if (type === 'TelegramInputFile | string') { type = 'MediaInput' @@ -132,6 +136,25 @@ class InterfaceService { type = 'ReplyMarkupUnion' } + // INFO: additional enums for IDE suggestions... + // TODO: probably autogenerate some of these from types into enums? + + if (field.name === 'type' && iface.name === 'MessageEntity') { + type += ' | Enums.MessageEntityType' + } + + if (field.name === 'status' && iface.name.startsWith('ChatMember')) { + type += ' | Enums.ChatMemberStatus.' + uppercaseFirst((field as Types.SchemaObjectString).default!) + } + + if (field.name === 'type' && iface.name === 'Sticker') { + type += ' | Enums.StickerType' + } + + if (field.name === 'type' && iface.name.startsWith('BotCommandScope')) { + type += ' | Enums.BotCommandScopeType.' + uppercaseFirst(undoSnakeCase((field as Types.SchemaObjectString).default!)) + } + const description = InterfaceService.generateDescription(field.description, 2) const property = `${description}\n${tab(field.name)}${field.required ? '' : '?'}: ${type}` @@ -232,6 +255,21 @@ class MethodService { returnType = 'Interfaces.Currency' } + // INFO: additional enums for IDE suggestions... + // TODO: probably autogenerate some of these from types into enums? + + if (field.name === 'emoji' && method.name === 'sendDice') { + returnType += ' | Enums.DiceEmoji' + } + + if (field.name === 'action' && method.name === 'sendChatAction') { + returnType += ' | Enums.ChatAction' + } + + if (field.name === 'sticker_format') { + returnType += ' | Enums.StickerFormat' + } + const property = `${description}\n${tab(field.name)}${field.required ? '' : '?'}: ${returnType}` response.fields.push(property) @@ -348,6 +386,8 @@ class GenerationService { return stripIndent` import { Readable } from 'stream' // INFO: for Interfaces.InputFile + import * as Enums from '../types/enums' + import { SoftString } from '../types/types' import { MediaInput } from '../common/media-source' @@ -367,6 +407,8 @@ class GenerationService { return stripIndent` import * as Interfaces from './telegram-interfaces' + import * as Enums from '../types/enums' + import { SoftString } from '../types/types' import { MediaInput } from '../common/media-source' @@ -377,7 +419,7 @@ class GenerationService { static generateAdditionalTypes () { return stripIndent` export type InputFile = string | Record | Buffer | Readable - export type PossibleParseMode = SoftString<'HTML' | 'Markdown' | 'MarkdownV2'> + export type PossibleParseMode = SoftString<'HTML' | 'Markdown' | 'MarkdownV2'> | Enums.ParseMode export type ReplyMarkupUnion = | TelegramInlineKeyboardMarkup | TelegramReplyKeyboardMarkup | TelegramReplyKeyboardRemove | TelegramForceReply | Keyboard | KeyboardBuilder | InlineKeyboard | InlineKeyboardBuilder | ForceReply | RemoveKeyboard