LoginSignup
0
0

More than 5 years have passed since last update.

Moleculer の Typetalk 通知アドオンを作った話

Last updated at Posted at 2019-03-10

概要

Moleculer の Typetalk 通知用アドオン moleculer-typetalk を作ったので紹介する記事です。

前提知識

Typetalk って何?という方は こちら

Moleculer とは?

Moleculer is a fast, modern and powerful microservices framework for Node.js. It helps you to build efficient, reliable & scalable services. Moleculer provides many features for building and managing your microservices.

Node.js 製のマイクロサービス向けのフレームワークです。日本語での紹介記事はあまり見かけませんが、結構コミュニティは活発なように見えます。

使い方

1) Typetalk でボットを作成します。

Screen Shot 2019-03-10 at 15.57.16.png

メッセージの投稿を行うので、topic.post にチェックを入れます

項目
ID moleculer-typetalk
Full Name moleculer-typetalk

2) サービスを作ります

サンプルコード

// index.js
const {ServiceBroker} = require("moleculer"),
    TypetalkService = require("moleculer-typetalk");

// Create broker
const broker = new ServiceBroker({logger: console});

// Load my service
broker.createService({
    mixins: [TypetalkService],
    name: "typetalk",
    settings: {
        token: YOUR_TYPETALK_TOKEN, // トークンを記載します。
        topicID: YOUR_TYPETALK_TOPIC_ID // トピックの ID を記載します。
    }
});

// Start server
broker.start().then(() => {
    broker
        .call("typetalk.post", {
            message: "Hello, Typetalk!"
        })
        .then(() => {
            // Do something...
        })
        .catch(() => {
            // Do something...
        });
});

3) 依存ライブラリをインストールします。

$ npm i --save moleculer moleculer-typetalk

4) 実行します。

$ node index.js

5) メッセージが投稿されます。

Screen Shot 2019-03-10 at 17.00.48.png

手順は以上となります。いかがだったでしょうか?フィードバック歓迎です :pray:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0