sysbot/tgscraper

从Telegram机器人API网页中提取方案的实用工具。

4.0.9 2024-07-02 10:28 UTC

This package is auto-updated.

Last update: 2024-08-25 16:58:37 UTC


README

License Required PHP Version Latest Stable Version Dependencies Code Quality

一个PHP库,用于从Telegram机器人API文档页面中提取JSON数据(并自动生成PHP类)。

变更日志

对最近的变化感兴趣?请查看这里

安装

使用composer安装库

  $ composer require sysbot/tgscraper --prefer-stable

(可选) 安装缓存包

  $ composer require sysbot/tgscraper-cache

从命令行使用

安装完成后,您可以使用CLI与库进行交互。

基本帮助和命令列表

  $ vendor/bin/tgscraper help

JSON

以可读的JSON格式提取最新的方案

  $ vendor/bin/tgscraper app:export-schema --readable botapi.json

或者,如果您想要一个与Postman兼容的JSON(感谢davtur19

  $ vendor/bin/tgscraper app:export-schema --postman botapi_postman.json

YAML

以YAML格式提取最新的方案

  $ vendor/bin/tgscraper app:export-schema --yaml botapi.yaml

OpenAPI

以JSON格式提取最新的OpenAPI方案

  $ vendor/bin/tgscraper app:export-schema --openapi botapi_openapi.json

或者,如果您更喜欢YAML

  $ vendor/bin/tgscraper app:export-schema --openapi --yaml botapi_openapi.yaml

存根

注意:由于Telegram可能会随时更改页面格式,所以请不要依赖于此库自动生成的存根,始终请检查代码!

TGScraper还可以生成您可以在库中使用的类存根。一个示例实现可以在Sysbot Telegram模块中找到。

使用Sysbot\Telegram作为命名空间前缀在out/目录中创建存根

  $ vendor/bin/tgscraper app:create-stubs --namespace-prefix "Sysbot\Telegram" out

所有版本

如果您想为每个机器人API版本生成所有方案和存根,您可以为做到这一点!

以下是将所有内容导出到out/目录的示例,方案以可读格式显示,存根使用Sysbot\Telegram作为命名空间前缀

  $ vendor/bin/tgscraper app:dump-schemas -r --namespace-prefix "Sysbot\Telegram" out

自定义格式

如果您对TGScraper生成的自定义格式感兴趣,您可以在这里找到其方案。