简体   繁体   中英

Hubot Slack attachment fields

Basically, this is what I want to achieve in Slack using Hubot. I've tried using

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

But this doesn't work. Does someone have an example of how I can make this work?

Thanks in advance ^^

Solved it by using

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

                    ]
                ]
            ]
        ];

And then inserted data using

        $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;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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