禅道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);
}

浙公网安备 33010602011771号