npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-msteams-host

v1.9.1

Published

Express utility for Microsoft Teams solutions

Downloads

2,012

Readme

Express utility for Microsoft Teams Apps

npm version npm MIT GitHub issues GitHub closed issues

This utility for Express is targeted for Microsoft Teams applications built generated by the Microsoft Teams Yeoman generator hosted on Express.

| @master | @preview | :--------:|:---------: Build Status|Build Status

The Middleware serves two major purposes:

  • Automatic routing of web services for Bots, Connectors and Outgoing Webhooks based on TypeScript decorators
  • Automatic routing of static pages for Tabs and Connectors

The middleware is automatically added to projects generated by the Microsoft Teams Yeoman generator.

Usage

For the automatic routing to work the following usage MUST be followed.

Creating a bot

Implementation and decorator usage for Bots

Bots MUST be implemented as a class extending the TeamsActivityHandler class and decorated using the BotDeclaration decorator.

import { BotDeclaration } from 'express-msteams-host';
import { MemoryStorage, ConversationState, TurnContext, TeamsActivityHandler, BotFrameworkAdapter } from 'botbuilder';

@BotDeclaration(
    '/api/messages',
    new MemoryStorage(),
    process.env.MICROSOFT_APP_ID,
    process.env.MICROSOFT_APP_PASSWORD)
export class myBot extends TeamsActivityHandler {

    public constructor(conversationState: ConversationState, private adapter: BotFrameworkAdapter) {
        super();
        ...
        this.onMessage(async (context: TurnContext): Promise<void> => {
           ...
        });
        ...
    }

}

Adding support for Calling in bots

NOTE: This method is deprecated and might be deleted in the future. For now it will remain available for usage.

When adding calling support to bots you need to create an incoming webhook method of your bot implementation. This method should be decorated with the BotCallingWebhook decorator and must follow the Express middleware signature. The endpoint you specify in the decorator, has to represent the calling endpoint you specify when registering the Teams Channel to your Bot in the Azure portal.

import { BotDeclaration, BotCallingWebhook } from 'express-msteams-host';
import express = require("express");

@BotDeclaration(...)
export class myBot extends TeamsActivityHandler {

    @BotCallingWebhook("/api/calling")
    public async onIcomingCall(req: express.Request, res: express.Response, next: express.NextFunction) {
        ...
    }
}

Decorators for Message Extensions

Message Extensions is implemented using the Bot Builder middleware botbuilder-teams-messagingextensions and when referenced in the bot implementation decorated with the MessageExtensionDeclarator decorator. The express-msteams-host will automatically hook up the correct messaging extensions with the correct bot.

In the implementation of the bot, define the message extensions as below. You are responsible for instantiating the object, you might want to add additional parameters or configuration.

import { BotDeclaration } from 'express-msteams-host';
import { MemoryStorage, ConversationState, TurnContext, TeamsActivityHandler, BotFrameworkAdapter } from 'botbuilder';
import { MyMessageExtension } from './MyMessageExtension';
import { TeamsAdapter } from "botbuilder-teams";

@BotDeclaration(
    '/api/messages',
    new MemoryStorage()
    process.env.MICROSOFT_APP_ID,
    process.env.MICROSOFT_APP_PASSWORD)
export class myBot extends TeamsActivityHandler {

    @MessageExtensionDeclaration('myMessageExtension')
    private _myMessageExtension: MyMessageExtension;

    public constructor(private conversationState: ConversationState, private adapter: BotFrameworkAdapter) {
        super();
        ...
        this._myMessageExtension = new MyMessageExtension();
        ...
    }

}

Decorator for Connectors

Connectors MUST be implemented as a class implementing the IConnector interface and decorated using the ConnectorDeclaration decorator.

import { ConnectorDeclaration, IConnector } from 'express-msteams-host';
import { Request } from "express";

@ConnectorDeclaration(
    '/api/connector/connect',
    '/api/connector/ping',
)
export class myConnector implements IConnector {
    Connect(req: Request): void {
        ...
    }

    Ping(req: Request): Promise<void>[] {
        ...
    }
}

Decorator for Outgoing Webhooks

Outgoing Webhooks MUST be implemented as a class implementing the IOutgoingWebhook interface and decorated using the OutgoingWebhookDeclaration decorator.

import { OutgoingWebhookDeclaration, IOutgoingWebhook } from 'express-msteams-host';
import * as express from 'express';

@OutgoingWebhookDeclaration('/api/webhook')
export class myOutgoingWebhook implements IOutgoingWebhook {
    public requestHandler(req: Express.Request, res: Express.Response, next: Express.NextFunction): any {
        ...
    }
}

Preventing pages to be iframed in other applications than Microsoft Teams

By using the PreventIframe decorator on server side classes pages can be declared to include a CSP that prohibts the pages from being iframed into other applications than Microsoft Teams.

import { PreventIframe } from "express-msteams-host";

@PreventIframe("/page/index.html")
export class MyPage {
    ...
}

Logging

To enable logging from this module you need to add msteams to the DEBUG environment variable. See the debug package for more information.

Example for Windows command line:

SET DEBUG=msteams

License

Copyright (c) Wictor Wilén. All rights reserved.

Licensed under the MIT license.