0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

掲示板の新着投稿をまとめてトークで通知する (LINE WORKS API 2.0)

Last updated at Posted at 2023-02-21

LINE WORKS の掲示板の新着投稿をトークで通知する Bot をつくってみました。
掲示板機能の通知機能もありますが、前日の新着投稿をまとめて Bot に知らせてもらうといった使い方を想定しています。

LINE WORKS の API 2.0 のトーク Bot と Board の API を使ってます。
Microsoft PowerAutomate を使ってます。

l_182795305_21_447fde98ba7cb5cb41600bfa2c9589b0.png

LINE WORKS API 2.0

以下の LINE WORKS API を使っています。

最新投稿リストの取得
https://developers.worksmobile.com/jp/reference/board-recent-post-get?lang=ja

メッセージの送信 - ユーザー指定
https://developers.worksmobile.com/jp/reference/bot-user-message-send?lang=ja

Text
https://developers.worksmobile.com/jp/reference/bot-send-text?lang=ja

LINE WORKS の Developer Console での API 2.0 の設定や、Bot の設定については LINE WORKS Developers サイトの記載や、Qiita 内の LINEWORKSタグの記事が参考になります。

Power Automate のクラウドフロー

Microsoft Power Automate でクラウド フローを作成します。

スケジュールで起動

[スケジュール] をトリガーにします。

l_182795305_11_512cf79a89e996a539cbf6af8ff83611.png

1 日に 1 回、決まった時間に起動させます。
image.png

LINE WORKS の Board API で掲示板の最新投稿リストを取得

掲示板 API のカスタム コネクタを作成しました。詳細は別記事にします。
l_182795305_13_7b9bfa55a4e9fd0d27d75592e32cf4e8.png

LINE WORKS API のレスポンスを解析

[JSON の解析コネクタ] でレスポンスを解析して返信を取り出します。
l_182795305_14_5b18afd7517295133dfa517c1c30c69b.png

"スキーマ" は以下です。

{
    "type": "object",
    "properties": {
        "posts": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "boardId": {
                        "type": "integer"
                    },
                    "postId": {
                        "type": "integer"
                    },
                    "title": {
                        "type": "string"
                    },
                    "readCount": {
                        "type": "integer"
                    },
                    "commentCount": {
                        "type": "integer"
                    },
                    "fileCount": {
                        "type": "integer"
                    },
                    "createdTime": {
                        "type": "string"
                    },
                    "modifiedTime": {
                        "type": "string"
                    },
                    "userId": {
                        "type": "string"
                    },
                    "userName": {
                        "type": "string"
                    },
                    "isMustRead": {
                        "type": "boolean"
                    },
                    "resourceLocation": {},
                    "isUnread": {
                        "type": "boolean"
                    }
                },
                "required": [
                    "boardId",
                    "postId",
                    "title",
                    "readCount",
                    "commentCount",
                    "fileCount",
                    "createdTime",
                    "modifiedTime",
                    "userId",
                    "userName",
                    "isMustRead",
                    "resourceLocation",
                    "isUnread"
                ]
            }
        },
        "responseMetaData": {
            "type": "object",
            "properties": {
                "nextCursor": {}
            }
        }
    }
}

前日の投稿を選択

"最新投稿リストの取得" の API の動作は以下です。

30日以内に登録された投稿リストを取得する。

このため、前日の記事のみ選択するように、日時コネクタを利用します。
1 日前の日時を生成し、タイムゾーン変換で JST にしつつ書式を整形します。
image.png

投稿の createdTime をタイムゾーン変換で書式を整形します。
l_182795305_16_94e80ff9d4f329c459dbedb9e013f997.png

条件で日付の合致するデータを選択します。
l_182795305_17_4725e7fe222a79dd3a5212b302c75b94.png

合致した場合は、以下の記事のカスタム コネクタを用いて Bot からメッセージを送信します。
https://qiita.com/iwaohig/items/4c47a2a1aabe2cb864a8

l_182795305_18_b74057e4ad41fbb9f29dfb671a713a10.png

フローは以上です。

動作確認

所定の時刻に、前日の新着投稿の通知が Bot から送られます。

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?