maknz / slack

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.
BSD 2-Clause "Simplified" License
1.17k stars 204 forks source link

Markdown in fields option does not work #39

Closed soullivaneuh closed 8 years ago

soullivaneuh commented 8 years ago

With the following message creation and sending:

public function sendNewTicket(Ticket $ticket)
{
    $message = $this->slack->createMessage();

    $fallback = sprintf(
        'Ticket #%d: %s - %s',
        $ticket->getId(),
        $ticket->getTitle(),
        $this->router->generate('ticket_show', ['id' => $ticket->getId()], UrlGeneratorInterface::ABSOLUTE_URL)
    );

    $message
        ->to(self::CHANNEL)
        ->attach(new Attachment([
            'fallback'   => $fallback,
            'title'      => sprintf('#%d: %s', $ticket->getId(), $ticket->getTitle()),
            'title_link' => $this->router->generate('ticket_show', ['id' => $ticket->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
            'color'      => $this->getPriorityColor($ticket->getPriority()),
            'fields'     => [
                [
                    'title' => 'Author',
                    'value' => sprintf(
                        '<%s|%s>',
                        $ticket->getAuthor()->getFullnameWithUsername(),
                        $this->router->generate('admin_user_show', ['id' => $ticket->getAuthor()->getId()], UrlGeneratorInterface::ABSOLUTE_URL)
                    ),
                    'short' => true,
                ],
                [
                    'title' => 'Organization',
                    'value' => $ticket->getOrganization() ? $ticket->getOrganization()->getName() : 'N/A',
                    'short' => true,
                ],
                [
                    'title' => 'Category',
                    'value' => $ticket->getCategory()->getName(),
                    'short' => true,
                ],
                [
                    'title' => 'Subject',
                    'value' => $ticket->getTitle(),
                    'short' => true,
                ],
                [
                    'title' => 'Priority',
                    'value' => $this->getPriorityStr($ticket->getPriority()),
                    'short' => true,
                ],
                [
                    'title' => 'Server',
                    'value' => $ticket->getServer() ? $ticket->getServer()->getName() : 'N/A',
                    'short' => true,
                ],
            ],
            'mrkdwn_in'   => ['fields'],
        ]))
    ;

    $this->slack->sendMessage($message);
}

I got the following result:

image

The Author fields show the raw markdown instead the needed link.

Is that an issue or a misconfiguration?

soullivaneuh commented 8 years ago

My bad, I reverse link and text on markdown format.

Sorry for the useless issue.