0.9.0 • Published 8 months ago

seratch-slack-types v0.9.0

Weekly downloads
25
License
MIT
Repository
github
Last release
8 months ago

Slack API TypeScript types generated by @seratch

https://www.npmjs.com/package/seratch-slack-types

This npm package is a collection of TypeScript type definition of Slack APIs.

Currently, the package support the following APIs.

  • API Methods (web-api)
  • Events API (events-api)
  • Real Time Messaging API (rtm-api)
  • Incoming payloads from Slack Platform (app-backend)
    • Dialogs (dialog_submission, cancellation, suggestion)
    • Interactive Messages (interactive_message, block_action)
    • Message Actions (message_action)
    • Slash Commands

How to use

import * as express from 'express';
import { Express, Request, Response } from 'express';

import * as Slack from '@slack/web-api';
import * as WebApi from 'seratch-slack-types/web-api';
import * as EventsApi from 'seratch-slack-types/events-api';

export const slackApi = new Slack.WebClient(process.env.SLACK_API_TOKEN);

export const app: Express = express();

app.post('/events', function (req: Request, res: Response) {
  const body = JSON.parse(req.body); // still "any" here

  if (body.type === 'url_verification') {
    // url verification
    res.status(200).send(body.event.challenge);

  } else if (body.type === 'event_callback' && body.event.type === 'message') { // still "any" here
    const payload = body as EventsApi.MessagePayload;
    // `payload.event.text` here is typesafe
    slackApi.api.test({ text: payload.event.text })
      .then((response: WebApi.ApiTestResponse) => { // `response` is typesafe
        if (response.ok) {
         // do something here
        } else {
         // do something here
        }
      }).catch(reason => {
        // do something here
      });
  } else {
    // do something here
  }
  res.status(200).json({ message: 'thanks!' });
});

How are the types generated

These types are generated from jSlack library's type definitions in Java + actual JSON responses fetched by running Slack Java SDK's unit tests. If you're interested in the details, take a look at Slack's Java SDK.

The coverage may not be 100% yet. A portion of the properties may be incorrect. If you find missing properties or something wrong, let us know here: https://github.com/seratch/seratch-slack-types/issues

License

The MIT License

0.9.0

8 months ago

0.8.0

1 year ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago