Webhook

WebHook 功能是Masterlab在执行某些动作和处理后,自动回调一个您设定的 http 地址。提交给http 地址的数据格式是json,具体数据 是根据具体的动作数据。

注:由于webhook支持的触发事件非常多,可能导致请求阻塞从而使整个系统性能下降,为了提高性能效率 webhook要求启用MasterlabSocket服务(建议使用swoole),详看Masterlab的安装结尾

Webhook支持的事件

Webhook 钩子的推送数据中带有丰富的 json 聚合信息,按信息的聚合单元区分,大致可分为如下几种

        $arr['事项'] = [
            Events::onIssueCreateBefore=>'创建事项之前',
            Events::onIssueCreateAfter=>'创建事项之后',
            Events::onIssueCreateChild=>'创建子任务之后',
            Events::onIssueUpdateBefore=>'更新事项之前',
            Events::onIssueUpdateAfter=>'更新事项之后',
            Events::onIssueDelete=>'删除事项',
            Events::onIssueClose=>'关闭事项',
            Events::onIssueFollow=>'关注事项',
            Events::onIssueUnFollow=>'取消关注事项',
            Events::onIssueConvertChild=>'转换子任务事项',
            Events::onIssueBatchDelete=>'批量删除事项',
            Events::onIssueBatchUpdate=>'批量更新事项',
            Events::onIssueBatchMoveProject=>'批量移动事项至新项目',
            Events::onIssueImportByExcel=>'导入事项',
            Events::onIssueRemoveChild=>'移除子任务',
            Events::onIssueUpload=>'附件上传',
            Events::onIssueMobileUpload=>'移动端附件上传',
            Events::onIssueDeleteUpload=>'删除附件',
        ];

        $arr['事项迭代'] = [
            Events::onIssueJoinSprint=>'事项加入迭代',
            Events::onIssueJoinClose=>'事项移动到关闭事项',
            Events::onIssueJoinBacklog=>'事项移动到待办事项',
        ];

        $arr['过滤器'] = [
            Events::onIssueAddAdvFilter=>'添加高级查询过滤器',
            Events::onIssueAddFilter=>'添加过滤器',
        ];

        $arr['评论'] = [
            Events::onIssueAddComment=>'添加评论',
            Events::onIssueDeleteComment=>'删除评论',
            Events::onIssueUpdateComment=>'编辑评论',
        ];

        $arr['项目'] = [
            Events::onProjectCreate=>'创建项目',
            Events::onProjectUpdate=>'编辑项目',
            Events::onProjectDelete=>'删除项目',
            Events::onProjectArchive=>'归档项目',
            Events::onProjectRecover=>'恢复项目',
        ];

        $arr['迭代管理'] = [
            Events::onSprintCreate=>'创建迭代',
            Events::onSprintUpdate=>'编辑迭代',
            Events::onSprintSetActive=>'设置迭代为进行时',
            Events::onSprintDelete=>'删除迭代',
        ];

        $arr['版本管理'] = [
            Events::onVersionCreate=>'创建版本',
            Events::onVersionUpdate=>'编辑版本',
            Events::onVersionDelete=>'删除办法',
            Events::onVersionRelease=>'发布版本',
        ];
        $arr['模块管理'] = [
            Events::onModuleCreate=>'创建模块',
            Events::onModuleUpdate=>'编辑模块',
            Events::onModuleDelete=>'删除模块',
        ];
        $arr['标签管理'] = [
            Events::onLabelCreate=>'标签模块',
            Events::onLabelUpdate=>'标签模块',
            Events::onLabelDelete=>'标签模块',
        ];
        $arr['分类管理'] = [
            Events::onCataloglCreate=>'分类模块',
            Events::onCatalogUpdate=>'分类模块',
            Events::onCatalogDelete=>'分类模块',
        ];
        $arr['项目成员'] = [
            Events::onProjectUserAdd=>'添加项目成员',
            Events::onProjectUserUpdateRoles=>'更新角色成员',
            Events::onProjectUserRemove=>'移除用户',
        ];
        $arr['项目角色'] = [
            Events::onProjectRoleAdd=>'添加项目角色',
            Events::onProjectRoleUpdate=>'编辑项目角色',
            Events::onProjectRoleRemove=>'删除项目角色',
            Events::onProjectRolePermUpdate=>'编辑角色权限',
            Events::onProjectRoleAddUser=>'角色添加用户',
            Events::onProjectRoleRemoveUser=>'角色移除用户',
        ];
        $arr['用户管理'] = [
            Events::onUserAddByAdmin=>'添加用户',
            Events::onUserUpdateByAdmin=>'编辑用户',
            Events::onUserActiveByAdmin=>'激活用户',
            Events::onUserDeleteByAdmin=>'删除用户',
            Events::onUserDisableByAdmin=>'禁用用户',
            Events::onUserBatchDisableByAdmin=>'批量禁用用户',
            Events::onUserBatchRecoveryByAdmin=>'批量恢复用户',
        ];
        $arr['用户相关'] = [
            Events::onUserRegister=>'用户注册',
            Events::onUserLogin=>'用户登录',
            Events::onUserlogout=>'用户注销',
            Events::onUserUpdateProfile=>'编辑资料',
        ];
        $arr['组织'] = [
            Events::onOrgCreate=>'创建组织',
            Events::onOrgUpdate=>'编辑组织',
            Events::onOrgDelete=>'删除组织',
        ];

Webhook创建

要创建一个新的Webhook,请按照以下步骤进行。首先要确保MasterlabSocket服务已经启动了。

  1. 以管理员身份登录,在"管理"/"Webhook"页面

  2. 输入webhook名称和提交的URL地址以及触发事件,为确保安全还可输入验证token webhook-create.png

  3. 保存后返回列表,启动webhook便可进行测试 例如提交的URL地址为 当前服务器的 /webhook.php 位于 masterlab/public/webhook.php 代码


// 用于测试webhook插件
require_once '../app/globals.php';

// 根据接收的数据进行你想要的业务操作
// ....
print_r($_POST);
// 将接收到webhook提交的数据写入到一个日志文件里,
$ret = file_put_contents(STORAGE_PATH . 'log/webhook.log', print_r($_POST['event_name'], true).print_r(json_decode($_POST['json'], true), true), FILE_APPEND);
print_r($ret);

当进行一些操作如创建项目创建事项后,便可在 storage/log/webhook.log 查看收到的调用数据

onIssueCreateAfter
Array
 (
     [summary] => 数据库每日自动备份
     [creator] => 1
     [reporter] => 1
     [created] => 1612680659
     [updated] => 1612680659
     [project_id] => 1
     [issue_type] => 3
     [priority] => 4
     [status] => 1
     [resolve] => 2
     [assignee] => 1
     [description] => 
     [module] => 1
     [environment] => 
     [sprint] => 2
     [weight] => 0
     [start_date] => 
     [due_date] => 
     [progress] => 0
     [gant_sprint_weight] => 999600000
     [id] => 161
     [project_info] => Array
         (
             [id] => 1
             [org_id] => 1
             [org_path] => default
             [name] => 示例项目
             [url] => 
             [lead] => 1
             [description] => Masterlab的示例项目
             [key] => example
             [pcounter] => 
             [default_assignee] => 1
             [assignee_type] => 
             [avatar] => project/avatar/1.png
             [category] => 0
             [type] => 0
             [type_child] => 0
             [permission_scheme_id] => 0
             [workflow_scheme_id] => 1
             [create_uid] => 1
             [create_time] => 1579247230
             [un_done_count] => 14
             [done_count] => 7
             [closed_count] => 4
             [archived] => N
             [issue_update_time] => 1583220515
             [is_display_issue_catalog] => 1
             [subsystem_json] => []
             [project_view] => issue
             [issue_view] => detail
             [issue_ui_scheme_id] => 0
             [project_tpl_id] => 1
             [default_issue_type_id] => 3
             [is_remember_last_issue] => 1
             [remember_last_issue_field] => ["issue_type","module","assignee","fix_version","labels"]
             [remember_last_issue_data] => {}
         )
 )

Masterlab - 404
404
您所访问的页面不存在或出错了
help->pageIndex no found;
debug
Sql:
Array
(
)
TRACE:
Array
(
)
GET:
Array
(
    [md] => webhook
    [_target] => Array
        (
            [0] => help
        )

)
POST:
Array
(
)
FILES:
Array
(
)
Include: 113
Array
(
    [0] => /data/www/masterlab-site/public/index.php
    [1] => /data/www/masterlab-site/app/globals.php
    [2] => /data/www/masterlab-site/vendor/autoload.php
    [3] => /data/www/masterlab-site/vendor/composer/autoload_real.php
    [4] => /data/www/masterlab-site/vendor/composer/ClassLoader.php
    [5] => /data/www/masterlab-site/vendor/composer/autoload_static.php
    [6] => /data/www/masterlab-site/vendor/ralouphie/getallheaders/src/getallheaders.php
    [7] => /data/www/masterlab-site/vendor/guzzlehttp/promises/src/functions_include.php
    [8] => /data/www/masterlab-site/vendor/guzzlehttp/promises/src/functions.php
    [9] => /data/www/masterlab-site/vendor/guzzlehttp/psr7/src/functions_include.php
    [10] => /data/www/masterlab-site/vendor/guzzlehttp/psr7/src/functions.php
    [11] => /data/www/masterlab-site/vendor/symfony/polyfill-mbstring/bootstrap.php
    [12] => /data/www/masterlab-site/vendor/guzzlehttp/guzzle/src/functions_include.php
    [13] => /data/www/masterlab-site/vendor/guzzlehttp/guzzle/src/functions.php
    [14] => /data/www/masterlab-site/vendor/adbario/php-dot-notation/src/helpers.php
    [15] => /data/www/masterlab-site/vendor/symfony/polyfill-php80/bootstrap.php
    [16] => /data/www/masterlab-site/vendor/danielstjules/stringy/src/Create.php
    [17] => /data/www/masterlab-site/vendor/symfony/polyfill-ctype/bootstrap.php
    [18] => /data/www/masterlab-site/vendor/mtdowling/jmespath.php/src/JmesPath.php
    [19] => /data/www/masterlab-site/vendor/songshenzong/support/src/StringsHelpers.php
    [20] => /data/www/masterlab-site/vendor/songshenzong/support/src/BashEchoHelpers.php
    [21] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/bootstrap.php
    [22] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/function.php
    [23] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/FilterSqlInject.php
    [24] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/HornetCoreException.php
    [25] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/HornetLogicException.php
    [26] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/ErrorHandler.php
    [27] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/HornetEngine.php
    [28] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/protocol/Iprotocol.php
    [29] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/protocol/Api.php
    [30] => /data/www/masterlab-site/vendor/hornet/framework/src/framework/protocol/Ajax.php
    [31] => /data/www/masterlab-site/app/function/autoload.php
    [32] => /data/www/masterlab-site/app/function/array.php
    [33] => /data/www/masterlab-site/app/function/common.php
    [34] => /data/www/masterlab-site/app/function/cryptojs-aes.php
    [35] => /data/www/masterlab-site/app/function/sql.php
    [36] => /data/www/masterlab-site/app/function/string.php
    [37] => /data/www/masterlab-site/app/function/system.php
    [38] => /data/www/masterlab-site/app/function/time.php
    [39] => /data/www/masterlab-site/app/function/upload_image.php
    [40] => /data/www/masterlab-site/app/function/web.php
    [41] => /data/www/masterlab-site/app/function/response_error.php
    [42] => /data/www/masterlab-site/app/function/excel.php
    [43] => /data/www/masterlab-site/vendor/symfony/yaml/Yaml.php
    [44] => /data/www/masterlab-site/vendor/symfony/yaml/Parser.php
    [45] => /data/www/masterlab-site/vendor/symfony/yaml/Inline.php
    [46] => /data/www/masterlab-site/vendor/symfony/yaml/Unescaper.php
    [47] => /data/www/masterlab-site/app/config/app.cfg.php
    [48] => /data/www/masterlab-site/app/constants.php
    [49] => /data/www/masterlab-site/app/config/common.cfg.php
    [50] => /data/www/masterlab-site/app/config/session.cfg.php
    [51] => /data/www/masterlab-site/app/ctrl/Help.php
    [52] => /data/www/masterlab-site/app/ctrl/BaseCtrl.php
    [53] => /data/www/masterlab-site/vendor/symfony/event-dispatcher/EventDispatcher.php
    [54] => /data/www/masterlab-site/vendor/symfony/event-dispatcher/EventDispatcherInterface.php
    [55] => /data/www/masterlab-site/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php
    [56] => /data/www/masterlab-site/app/model/SettingModel.php
    [57] => /data/www/masterlab-site/app/model/BaseDictionaryModel.php
    [58] => /data/www/masterlab-site/app/model/CacheModel.php
    [59] => /data/www/masterlab-site/app/model/DbModel.php
    [60] => /data/www/masterlab-site/app/model/BaseModel.php
    [61] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php
    [62] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Configuration.php
    [63] => /data/www/masterlab-site/vendor/doctrine/event-manager/lib/Doctrine/Common/EventManager.php
    [64] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/MySQL/Driver.php
    [65] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
    [66] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
    [67] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver.php
    [68] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php
    [69] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php
    [70] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php
    [71] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Connection.php
    [72] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/TransactionIsolationLevel.php
    [73] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/ParameterType.php
    [74] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/FetchMode.php
    [75] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
    [76] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Connection.php
    [77] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
    [78] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php
    [79] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOQueryImplementation.php
    [80] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Statement.php
    [81] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
    [82] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Statement.php
    [83] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ResultStatement.php
    [84] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Result.php
    [85] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatementImplementations.php
    [86] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Events.php
    [87] => /data/www/masterlab-site/lib/MyRedis.php
    [88] => /data/www/masterlab-site/vendor/doctrine/dbal/lib/Doctrine/DBAL/SQLParserUtils.php
    [89] => /data/www/masterlab-site/app/classes/UserAuth.php
    [90] => /data/www/masterlab-site/app/ctrl/Resource.php
    [91] => /data/www/masterlab-site/lib/parsedown/Parsedown.php
    [92] => /data/www/masterlab-site/app/view/help.php
    [93] => /data/www/masterlab-site/app/view/common/header-meta.php
    [94] => /data/www/masterlab-site/app/view/common/header-style.php
    [95] => /data/www/masterlab-site/app/view/common/header-script.php
    [96] => /data/www/masterlab-site/app/view/common/body-header.php
    [97] => /data/www/masterlab-site/app/view/common/common-footer.php
    [98] => /data/www/masterlab-site/app/view/common/siteFooter.php
    [99] => /data/www/masterlab-site/app/view/modal/login.php
    [100] => /data/www/masterlab-site/app/view/modal/signup.php
    [101] => /data/www/masterlab-site/app/view/modal/get-started.php
    [102] => /data/www/masterlab-site/app/view/modal/try.php
    [103] => /data/www/masterlab-site/app/view/modal/trial.php
    [104] => /data/www/masterlab-site/app/view/modal/buy-premium.php
    [105] => /data/www/masterlab-site/app/view/modal/loading.php
    [106] => /data/www/masterlab-site/app/view/modal/signup-failed.php
    [107] => /data/www/masterlab-site/app/view/modal/existing-account.php
    [108] => /data/www/masterlab-site/app/view/modal/unsupported-browser.php
    [109] => /data/www/masterlab-site/app/view/modal/calculate.php
    [110] => /data/www/masterlab-site/app/view/modal/sso-signup.php
    [111] => /data/www/masterlab-site/app/view/modal/i18n.php
    [112] => /data/www/masterlab-site/app/view/exception.php
)