Telegex
为什么 Telegex 1.0 是正确无误的框架
本文章是早期 Telegex 作者在外部宣传时发表的内容,它还欠缺修改以更适应博客读者。 背景 大概三年前,我们创建了一个叫做 Telegex 的库。它那时候只是一个简单的 Telegram Bot API 客户端,虽然它的实现也是用数据来生成一个个调用 API 的函数,但是面对 Bot API 的频繁更新,它仍然显得适配乏力。 最近,我们完全重新的设计了这个库。它在适配新的 Bot API 的速度上是无与伦比的,因为只需要一条命令。秘密在于它基于官方文档“数据”来自动生成代码,只需要更新一下文档便可适配所有最新变化。包括 API 变动、注释变动,任何类型和字段的变动。 为什么叫文档数据? 因为文档真的解析成了数据。我们将官方文档页面中的几乎所有的有效内容转换为了 JSON 格式,并上传到独立的仓库中(telegex/api_doc.json)。包括所有类型、方法和注释。 从文档生成 JSON 文件是 Mix 任务,位于 telegex/lib/mix/tasks/gen.doc_json.ex 文件。 对于类型 我将类型转换为 JSON,如: { "name": "WebhookInfo", "description": "Describes the current status of a webhook.", "fields": [ { "name": "url", "type": "String", "description": "Webhook URL, may be empty if webhook is not set up", "optional": false }, { "name": "has_custom_certificate", "type": "Boolean", "description": "True, if a custom certificate was provided for webhook certificate checks", "optional": false }, { "name": "pending_update_count", "type": "Integer", "description": "Number of updates awaiting delivery", "optional": false }, { "name": "ip_address", "type": "String", "description": "Optional.