PHP code example of shahil / msgraph

1. Go to this page and download the library: Download shahil/msgraph library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shahil / msgraph example snippets


return [
    'client_id' => env('MICROSOFT_CLIENT_ID'),
    'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
    'tenant_id' => env('MICROSOFT_TENANT_ID'),
    'scope' => env('MICROSOFT_SCOPE'),
    'username' => env('MICROSOFT_USERNAME'),
    'password' => env('MICROSOFT_PASSWORD'),
];

   use Shahil\MSGraph\Facades\MSGraph;

   $userId = MSGraph::getUserId('[email protected]');
   

   use Shahil\MSGraph\Facades\MSGraph;

   MSGraph::sendMessageToUser('[email protected]', 'Hello from Laravel!');
   

   use Shahil\MSGraph\Facades\MSGraph;

   // Retrieve the group chat ID by its name
   $chatId = MSGraph::getChatIdByGroupName('Your Group Name');

   // Send a message to the group
   MSGraph::sendMessageToGroup($chatId, 'Hello group members!');
   

   use Shahil\MSGraph\Facades\MSGraph;

   $adaptiveCardPayload = [
       'type' => 'AdaptiveCard',
       'version' => '1.4',
       'body' => [
           ['type' => 'TextBlock', 'text' => 'Welcome to MS Graph Integration!']
       ],
       'actions' => [
           ['type' => 'Action.OpenUrl', 'title' => 'Learn More', 'url' => 'https://learn.microsoft.com/graph/']
       ]
   ];

   MSGraph::sendAdaptiveCardToUser('[email protected]', $adaptiveCardPayload);
   

   use Shahil\MSGraph\Facades\MSGraph;

   $chatId = MSGraph::getChatIdByGroupName('Your Group Name');
   

   use Shahil\MSGraph\Facades\MSGraph;

   $targetUserId = MSGraph::getUserId('[email protected]');
   $chatId = MSGraph::getChatId($targetUserId);
   

namespace App\Http\Controllers;

use Shahil\MSGraph\Facades\MSGraph;

class TeamsController extends Controller
{
    public function sendGroupMessage()
    {
        try {
            $chatId = MSGraph::getChatIdByGroupName('Your Group Name');
            MSGraph::sendMessageToGroup($chatId, 'Hello, team!');
            return response()->json(['success' => 'Message sent to the group successfully.']);
        } catch (\Exception $e) {
            return response()->json(['error' => $e->getMessage()]);
        }
    }
}
bash
   php artisan vendor:publish --tag=msgraph-config
   
bash
php artisan test