PHPackages                             alexkargin/msteams-bot-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. alexkargin/msteams-bot-php

ActiveLibrary[API Development](/categories/api)

alexkargin/msteams-bot-php
==========================

PHP Wrapper for Microsoft Teams Bot API

v1.0.1(5y ago)3535[1 issues](https://github.com/alexkargin/msteams-bot-php/issues)MITPHPPHP ^7.4

Since May 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alexkargin/msteams-bot-php)[ Packagist](https://packagist.org/packages/alexkargin/msteams-bot-php)[ RSS](/packages/alexkargin-msteams-bot-php/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

PHP Teams Bot [![Build Status](https://camo.githubusercontent.com/293afb735b587e65393bb2c76907d8faee72a3f297cbba8562dd6ca0c5690381/68747470733a2f2f7472617669732d63692e636f6d2f616c65786b617267696e2f6d737465616d732d626f742d7068702e7376673f6272616e63683d6d61696e)](https://travis-ci.com/github/alexkargin/msteams-bot-php)
==============================================================================================================================================================================================================================================================================================================================

[](#php-teams-bot-)

A simple php library for creating bots for Microsoft Teams

Requirements
------------

[](#requirements)

- `PHP 7.4`
- Package uses `Guzzle Client` for API requests

Getting started
---------------

[](#getting-started)

### Installation

[](#installation)

Install using composer:

```
composer require alexkargin/msteams-bot-php
```

### Create a bot

[](#create-a-bot)

Create a new bot in [Teams App Studio](https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/app-studio-overview).

You should get Bot ID and Password at this step.

### Basic Usage

[](#basic-usage)

```
include __DIR__ . '/vendor/autoload.php';

use TeamsBot\Bot;
use TeamsBot\Exception\TeamsBotException;
use TeamsBot\Exception\TeamsBotTokenException;

try {
    $bot = new TeamsBot\BotListener('bot_id', 'password');

    // Handled on any request
    $bot->onAny(static function (Bot $bot) {
        // Sends a simple text message
        if(!empty($bot->context->getText())) {
            $bot->reply('You send ' . $bot->context->getText());
        }
    });

    // Handled when user add bot
    $bot->onStartPersonalChat(static function (Bot $bot) {
        // Sends a simple text message
        $bot->reply('Hi, ' . $bot->context->getFromName());
    });

    // Handled when user sends 'test' to bot
    $bot->onText('test', function (Bot $bot) {
        // create Activity
        $message = $bot->createMessage();
        // add Hero Card
        $att = new TeamsBot\Card\HeroCard();
        $att->setContentFromJson('
{
"buttons": [
    {
        "type": "messageBack",
        "text": "Send request to bot",
        "value": "{\"property\": \"propertyValue\" }"
   }
]
}
        ');
        $message->addAttachment($att);
        // send new message
        $bot->postMessage($message);
    });

    // Handled when user send form to bot
    // for example, Hero Card from previous handler
    $bot->onSubmitForm(function (Bot $bot) {
        $message = $bot->createMessage();
        $message->setText('Received data: ' . json_encode($bot->context->getFormData(), JSON_THROW_ON_ERROR));
        // update Activity with form
        $bot->updateMessage($message);
    });

} catch (TeamsBotException $e) {
} catch (TeamsBotTokenException $e) {

}
```

Important! Validating incoming requests
---------------------------------------

[](#important-validating-incoming-requests)

The package does not contain ways to check the validity of incoming requests. You can implement this check according to the [documentation](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-authentication?view=azure-bot-service-4.0), or use a different check method. For example, add a secret value to the handler address and check it.

Token caching
-------------

[](#token-caching)

By default, each bot instance receives a new token for sending messages. To speed up sending messages, the token can be cached for N seconds. For example, using the package [Stash](https://github.com/tedious/Stash)

Installing the package

```
composer require tedivm/stash
```

And use it

```
    $bot = new TeamsBot\BotListener('bot_id', 'password');
    // use filesystem driver
    $pool = new Stash\Pool(new Stash\Driver\FileSystem([]));
    $item = $pool->getItem('token');
    $token = $item->get();
    if($item->isMiss())
    {
        // get new token
        $token = $bot->token->get();
        // Cache expires $token['expires_in']
        $expiration = new DateTime('@'.$token['expires_in']);
        $item->expiresAfter($expiration);
        $item->set($token);
        $pool->save($item);
    }

    // set token
    $bot->token->set($token);
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

1879d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/62253635?v=4)[alexkargin](/maintainers/alexkargin)[@alexkargin](https://github.com/alexkargin)

---

Top Contributors

[![akargin32](https://avatars.githubusercontent.com/u/80886731?v=4)](https://github.com/akargin32 "akargin32 (12 commits)")[![alexkargin](https://avatars.githubusercontent.com/u/62253635?v=4)](https://github.com/alexkargin "alexkargin (2 commits)")

---

Tags

botmicrosoftteamsbotphpphpbotbot apiTeams

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexkargin-msteams-bot-php/health.svg)

```
[![Health](https://phpackages.com/badges/alexkargin-msteams-bot-php/health.svg)](https://phpackages.com/packages/alexkargin-msteams-bot-php)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M733](/packages/sylius-sylius)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k409.0k6](/packages/theodo-group-llphant)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[keboola/storage-api-client

Keboola Storage API PHP Client

10405.9k39](/packages/keboola-storage-api-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
