繁体   English   中英

Hubot Slack附件字段

[英]Hubot Slack attachment fields

基本上, 就是我想使用Hubot在Slack中实现的目标。 我试过使用

      attachment = 
        fields: [
              {
                title: "User info"
                value: json.user
                short: false
              }
        ]

但这是行不通的。 有人举我如何做这项工作的例子吗?

在此先感谢^^

通过使用解决

$attachments = [
            'text' => "Active codebases: (total = $total)",
            'attachments' => [
                [
                    'color' => '#3333ff',
                    'fields' => [

                    ]
                ]
            ]
        ];

然后使用插入数据

        $items = $codebases;

        foreach ($items as $item)
        {
            if(LinkedUser::where('codebase_id', $item->id)->get() !== null) {
                $linkedusers = LinkedUser::where('codebase_id', $item->id)->get();

                $userlist = "";

                $i = 0;
                $len = count($linkedusers);
                foreach ($linkedusers as $linkeduser)
                {
                    if ($i == $len - 1) {
                        $userlist .= $linkeduser->user_name;
                    } else {
                        $userlist .= $linkeduser->user_name . ",\n";
                    }
                    $i++;
                }

                $a = [
                    'title' => $item->name,
                    'value' => $userlist,
                    'short' => true
                ];
                $attachments['attachments'][0]['fields'][] = $a;
            }
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM