Search code examples
coffeescriptslackhubot

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 ^^


Solution

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