Giter VIP home page Giter VIP logo

microsoft-teams's Introduction

Microsoft Teams Notifications Channel for Laravel

Latest Version on Packagist Software License Total Downloads

This package makes it easy to send notifications using Microsoft Teams with Laravel 5.5+, 6.x, 7.x, 8.x, 9.x, 10.x and 11.x

return MicrosoftTeamsMessage::create()
    ->to(config('services.microsoft_teams.sales_url'))
    ->type('success')
    ->title('Subscription Created')
    ->content('Yey, you got a **new subscription**. Maybe you want to contact him if he needs any support?')
    ->button('Check User', 'https://foo.bar/users/123');

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/microsoft-teams

Next, if you're using Laravel without auto-discovery, add the service provider to config/app.php:

'providers' => [
    // ...
    NotificationChannels\MicrosoftTeams\MicrosoftTeamsServiceProvider::class,
],

Setting up the Connector

Please check out this for setting up and adding a webhook connector to your Team's channel. Basic Markdown is supported, please also check out the message card reference article which goes in more detail about the do's and don'ts.

Setting up the MicrosoftTeams service

Then, configure your webhook url:

Add the following code to your config/services.php:

// config/services.php
...
'microsoft_teams' => [
    'webhook_url' => env('TEAMS_WEBHOOK_URL'),
],
...

You can also add multiple webhooks if you have multiple teams or channels, it's up to you.

// config/services.php
...
'microsoft_teams' => [
    'sales_url' => env('TEAMS_SALES_WEBHOOK_URL'),
    'dev_url' => env('TEAMS_DEV_WEBHOOK_URL'),
],
...

Usage

Now you can use the channel in your via() method inside the notification:

use Illuminate\Notifications\Notification;
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;

class SubscriptionCreated extends Notification
{
    public function via($notifiable)
    {
        return [MicrosoftTeamsChannel::class];
    }

    public function toMicrosoftTeams($notifiable)
    {
        return MicrosoftTeamsMessage::create()
            ->to(config('services.microsoft_teams.sales_url'))
            ->type('success')
            ->title('Subscription Created')
            ->content('Yey, you got a **new subscription**. Maybe you want to contact him if he needs any support?')
            ->button('Check User', 'https://foo.bar/users/123');
    }
}

Instead of adding the to($url) method for the recipient you can also add the routeNotificationForMicrosoftTeams method inside your Notifiable model. This method needs to return the webhook url.

public function routeNotificationForMicrosoftTeams(Notification $notification)
{
    return config('services.microsoft_teams.sales_url');
}

On-Demand Notification Usage

To use on demand notifications you can use the route method on the Notification facade.

Notification::route(MicrosoftTeamsChannel::class,null)
    ->notify(new SubscriptionCreated());

Available Message methods

  • to(string $webhookUrl): Recipient's webhook url.
  • title(string $title): Title of the message.
  • summary(string $summary): Summary of the message.
  • type(string $type): Type which is used as theme color (any valid hex code or one of: primary|secondary|accent|error|info|success|warning).
  • content(string $content): Content of the message (Markdown supported).
  • button(string $text, string $url = '', array $params = []): Text and url of a button. Wrapper for an potential action.
  • action(string $text, $type = 'OpenUri', array $params = []): Text and type for a potential action. Further params can be added depending on the action. For more infos about different types check out this link.
  • options(array $options, $sectionId = null): Add additional options to pass to the message payload object.

Sections

It is possible to define one or many sections inside a message card. The following methods can be used within a section

  • addStartGroupToSection($sectionId = 'standard_section'): Add a startGroup property which marks the start of a logical group of information.
  • activity(string $activityImage = '', string $activityTitle = '', string $activitySubtitle = '', string $activityText = '', $sectionId = 'standard_section'): Add an activity to a section.
  • fact(string $name, string $value, $sectionId = 'standard_section'): Add a fact to a section (Supports Markdown).
  • image(string $imageUri, string $title = '', $sectionId = 'standard_section'): Add an image to a section.
  • heroImage(string $imageUri, string $title = '', $sectionId = 'standard_section'): Add a hero image to a section.

Additionally the title, content, button and action can be also added to a section through the optional params value:

  • title(string $title, array $params = ['section' => 'my-section']): Title of the message and add it to my-section.
  • content(string $content, array $params = ['section' => 'my-section']): Content of the message and add it to my-section (Markdown supported).
  • button(string $text, string $url = '', array $params = ['section' => 'my-section']): Text and url of a button and add it to my-section.
  • action(string $text, $type = 'OpenUri', array $params = ['section' => 'my-section']): Text and type of an potential action and add it to my-section.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

microsoft-teams's People

Contributors

atymic avatar cannonb4ll avatar douglasdc3 avatar freekmurze avatar jmurphy45 avatar joshualicense avatar laravel-shift avatar seb33300 avatar tob0t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

microsoft-teams's Issues

Mentioning users in message & link with text

How do I mention users in the content/title of a message?

I tried doing:
@my Name
@my_email
@microsoft_user_id

<at>My Name</at>
<at>my_email</at>
<at>microsoft_user_id</at>
return MicrosoftTeamsMessage::create()
            ->to(config('services.microsoft_teams.webhook_url'))
            ->type($contents[1])
            ->title($contents[0])
            ->content($contents[0], [
                [
                    'entities' => [
                        [
                            'type' => 'mention',
                            'text' => '<at>' . $this->users[0]->getFullName() . '</at>',
                            'mentioned' => [
                                'id' => $this->users[0]->email,
                                'name' => $this->users[0]->getFullName()
                            ]
                        ],
                        [
                            'type' => 'mention',
                            'text' => '<at>' . $this->users[0]->email . '</at>',
                            'mentioned' => [
                                'id' => {microsoft_user_id}',
                                'name' => $this->users[0]->getFullName()
                            ]
                        ]
                    ]
                ]
            ])

But I just can't seem to get a proper mention.

help to sending message

Hello, I would like to send an online message after a task, is it possible? Could you give me an example?

Note: I have not been able to send without creating a Controller, that's why my query.

Thank you

Example code

    $channel = new MicrosoftTeamsChannel(config('services.microsoft_teams.DTES_url'));

    $teamsMessage= MicrosoftTeamsMessage::create()
        ->type('warning')
        ->title('Cliente No Encontrado')
        ->content('Test<br><br>');

    $response = $channel->send(null, **$teamsMessage);**

[Feature] Dismiss Button

is it possible to make a button disappear after clicking it?

or dismiss the whole card like polly?

Thank you

image

images ?

I have tried all the possible options to add an image, but it never shows:


        $teams->image('https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Seattle_monorail01_2008-02-25.jpg/1024px-Seattle_monorail01_2008-02-25.jpg');
        $teams->heroImage('https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Seattle_monorail01_2008-02-25.jpg/1024px-Seattle_monorail01_2008-02-25.jpg');

        $teams->options([
            // "@type" => "application/vnd.microsoft.card.thumbnail",
            "title" => "title",
            "subtitle" => "subtitle",
            "text" => "text",
            "image" => "https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Seattle_monorail01_2008-02-25.jpg/1024px-Seattle_monorail01_2008-02-25.jpg",
            "images" => ["url" => "https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Seattle_monorail01_2008-02-25.jpg/1024px-Seattle_monorail01_2008-02-25.jpg" ]
        ]);

I tried with all @types in https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference: Thumbnail, Cards, Heros, ...

Also this is the further I get:

$teams->options([
                "sections" => [
                    [
                        "images" => [
                            [
                                "image" => $image
                            ]
                        ]
                    ]
                ]
            ]);

This generates this JSON payload (I took it exactly before it sends to Microsoft)
$response = $this->microsoftTeams->send($message->getWebhookUrl(), $message->toArray());

{
    "@type": "MessageCard",
    "@context": "https:\/\/schema.org\/extensions",
    "summary": "summary",
    "themeColor": "#1976D2",
    "text": "text",
    "title": "title",
    "sections": [
        {
            "images": [
                {
                    "image": "http://connectorsdemo.azurewebsites.net/images/WIN12_Anthony_02.jpg"
                }
            ]
        }
    ]
}

And this works PERFECTLY in https://messagecardplayground.azurewebsites.net/

But not through this module.

Any way to really add an image ?
The only thing I got is an avatar (little circle image), but it's not a big image ;-)
I've tried with gif, jpg, png, ... even the image of the Microsoft documentation (the monorail :-) )

How to obtain individual user's webhook URL for config via User model DB

Hi, I've just been browsing the Microsoft Teams notification channel. In my web application, users have the option to intgrate Microsoft Teams to receive notifications, by design, each user in my system needs their own webhook URL, but the assumption of this channel is that only one Microsoft Teams account will be set up and used as the config doesn't seem to mention anything about pulling from the DB.

How can I obtain the user's webhook URL that they desire in my User model?

Too few arguments to function ::routeNotificationFor(), 1 passed, 2 expected

On line 38 of MicrosoftTeamsChannel, you're calling

            $to = $notifiable->routeNotificationFor('microsoftTeams');

However, routeNotificationFor should have a 2nd argument which is the $notification object. This SHOULD be changed to

            $to = $notifiable->routeNotificationFor('microsoftTeams', $notification);

405 Client Error? No response body

Trying to set it up so it sends me a message when a new user is created. But I keep getting and no reason as to why. Was hoping someone else has seen this before.

Microsoft Teams responded with an error 405 - Client error: POST https://teams.microsoft.com/l/channel/19%3ab078bb283c3843ec89b3849330d32773%40thread.skype/TestChat?groupId=a0dfa142-c15d-46d0-b400-071d26173017&tenantId=df2dd858-6005-4352-b666-dd038f050723` resulted in a 405 Method Not Allowed response`

Timeout for requests

Hi,

thanks for your great package, it has worked flawlessly for 2 years in my company.

But I think it would be great to add a timeout option for requests, something in config files which would be 0 by default but can be configured for a timeout.

Context :
There were some problems with incoming teams webhooks this monday and tuesday (with absolutely no communication from microsoft about the issue by the way) which resulted in a disruption of our ticketing system (which sends notifcations to teams) at my company.

random 500 and 503 errors which we can catch and log, without any disruption of service, but the webhook would sometimes not respond at all, which resulted in a 504 error for our customers.

I had to fork the project in a private package and add this functionnality, since this was critical for us and I could'nt wait for an approval of a PR, but let me know if you're interested so I can make it a little cleaner and propose a PR.

Channel Launch

  • Code Review
  • Add to website
  • Create packagist package
  • Github actions
  • Style CI
  • Scrutinizer
  • Add badges

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.