禅道webhook增加自定义消息内容

禅道的默认webhook通知是没有太多信息的,比如,指派给谁了,这里就需要我们自己修改

module/webhook/model.php 文件中 buildData 方法 。

$assignedToUserName = $this->dao->select('realname')->from(TABLE_USER)->where('account')->eq($object->assignedTo)->fetch('realname'); 

$text           = $title . ' ' . "[#{$objectID}::{$object->$field}](" . $host . $viewLink . ")" . "\n指派给:" . $assignedToUserName; 
      

public function buildData($objectType, $objectID, $actionType, $actionID, $webhook)
    {
        /* Validate data. */
        if(!isset($this->lang->action->label)) $this->loadModel('action');
        if(!isset($this->lang->action->label->$actionType)) return false;
        if(empty($this->config->objectTables[$objectType])) return false;
        $action = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->eq($actionID)->fetch();
        if(!$action) return false;

        if($webhook->products)
        {
            $webhookProducts = explode(',', trim($webhook->products, ','));
            $actionProduct   = explode(',', trim($action->product, ','));
            $intersect       = array_intersect($webhookProducts, $actionProduct);
            if(!$intersect) return false;
        }
        if($webhook->executions)
        {
            if(strpos(",$webhook->executions,", ",$action->execution,") === false) return false;
        }

        static $users = array();
        if(empty($users)) $users = $this->loadModel('user')->getList();

        $object         = $this->dao->select('*')->from($this->config->objectTables[$objectType])->where('id')->eq($objectID)->fetch();
        $field          = $this->config->action->objectNameFields[$objectType];
        $host           = empty($webhook->domain) ? common::getSysURL() : $webhook->domain;
        
        //修改这里
        $assignedToUserName = $this->dao->select('realname')->from(TABLE_USER)->where('account')->eq($object->assignedTo)->fetch('realname'); 
        $viewLink       = $this->getViewLink($objectType == 'kanbancard' ? 'kanban' : $objectType, $objectType == 'kanbancard' ? $object->kanban : $objectID);
        $objectTypeName = ($objectType == 'story' and $object->type == 'requirement') ? $this->lang->action->objectTypes['requirement'] : $this->lang->action->objectTypes[$objectType];
        $title          = $this->app->user->realname . $this->lang->action->label->$actionType . $objectTypeName;
        $host           = (defined('RUN_MODE') and RUN_MODE == 'api') ? '' : $host;
        if (empty($assignedToUserName)) {
            $text           = $title . ' ' . "[#{$objectID}::{$object->$field}](" . $host . $viewLink . ")"; 
        } else {
            $text           = $title . ' ' . "[#{$objectID}::{$object->$field}](" . $host . $viewLink . ")" . "\n指派给:" . $assignedToUserName;  //修改这里
        }
        $action->text   = $text;

        $mobile = '';
        $email  = '';
        if(in_array($objectType, $this->config->webhook->needAssignTypes) && !empty($object->assignedTo))
        {
            $assignedTo = $this->loadModel('user')->getById($object->assignedTo);
            if($assignedTo)
            {
                $mobile = $assignedTo->mobile;
                $email  = $assignedTo->email;
            }
        }
      return $this->getDataByType($webhook, $action, $title, $text, $mobile, $email, $objectType, $objectID);
    }

 

posted @   AnPant  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示