1.2.0-preview • Published 8 years ago

express-msteams-host v1.2.0-preview

Weekly downloads
600
License
MIT
Repository
github
Last release
8 years ago

Express utility for Microsoft Teams Apps

npm version

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

@master@preview
Build StatusBuild 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 SHOULD be implemented as a class extending the TeamsBot class and decorated using the BotDeclaration decorator.

import { BotDeclaration, TeamsBot } from 'express-msteams-host';
import * as teamBuilder from 'botbuilder-teams';

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

    public constructor(connector: teamBuilder.TeamsChatConnector) {
        super(connector);
        ...
    }

}

A bot could also be implemented by implementing the IBot interface and the BotDeclaration decorator, which is how it was done in version 1.0.? and earlier. But such an implementation would require manual implementation of message extensions.

Decorators for Message Extensions

Message Extensions MUST be a class implementing the IMessageExtension interface and when declared in the bot implementation decorated with the MessageExtensionDeclarator decorator.

import { IMessageExtension } from 'express-msteams-host';


export default class MyMessageExtension implements IMessageExtension {
    constructor(private bot: builder.UniversalBot) {
    }

    public onQuery(event: builder.IEvent, query: teamBuilder.ComposeExtensionQuery, callback: (err: Error, result: teamBuilder.IComposeExtensionResponse, statusCode: number) => void): void {
       ...
    }

    // this is used when canUpdateConfiguration is set to true 
    public onQuerySettingsUrl(event: builder.IEvent, query: teamBuilder.ComposeExtensionQuery, callback: (err: Error, result: teamBuilder.IComposeExtensionResponse, statusCode: number) => void): void {
        ...
    }

    public onSettingsUpdate(event: builder.IEvent, query: teamBuilder.ComposeExtensionQuery, callback: (err: Error, result: teamBuilder.IComposeExtensionResponse, statusCode: number) => void): void {
       ...
    }

}

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, and then you must invoke the registerMessageExtensions() method.

import { BotDeclaration, TeamsBot, MessageExtensionDeclaration } from 'express-msteams-host';
import * as teamBuilder from 'botbuilder-teams';
import { MyMessageExtension } from './MyMessageExtension';

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

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

    public constructor(connector: teamBuilder.TeamsChatConnector) {
        super(connector);
        ...

        this._myMessageExtension = new MyMessageExtension(this.universalBot);

        super.registerMessageExtensions();
    }

}

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',
    'web/myConnectorConnect.ejs',
    '/myConnectorConnected.html'
)
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 IOutdegoingWebhook 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 {
        ...
    }
}

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.

1.9.1

4 years ago

1.9.1-preview.1

4 years ago

1.9.0

4 years ago

1.9.0-preview2

4 years ago

1.9.0-preview

5 years ago

1.8.0

5 years ago

1.8.0-preview

5 years ago

1.7.0

6 years ago

1.7.0-preview2

6 years ago

1.7.0-preview

6 years ago

1.6.2

6 years ago

1.6.2-preview3

6 years ago

1.6.2-preview2

6 years ago

1.6.2-preview

6 years ago

1.6.1

6 years ago

1.6.1-preview

6 years ago

1.6.0

6 years ago

1.6.0-preview2

6 years ago

1.6.0-preview

6 years ago

1.5.2

6 years ago

1.5.2-preview

6 years ago

1.5.1

7 years ago

1.5.1-preview

7 years ago

1.4.2-preview2

7 years ago

1.5.0

7 years ago

1.4.2-preview

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.4.0-preview3

7 years ago

1.4.0-preview2

7 years ago

1.4.0-preview

7 years ago

1.3.1

7 years ago

1.3.1-Preview

7 years ago

1.3.0

7 years ago

1.3.0-preview4

7 years ago

1.3.0-preview3

7 years ago

1.3.0-preview2

7 years ago

1.3.0-preview

7 years ago

1.2.0-preview2

7 years ago

1.2.0-preview

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago