LoginSignup
0
1

More than 5 years have passed since last update.

LINE Bot SDK for Node.js で、 「はい」「いいえ」を確認するメッセージを送りたい

Last updated at Posted at 2018-07-13

LINE のチャットボットで、テンプレートメッセージという、Botから選択できるUIがある。

こういうやつ

image.png

これを Node.js の SDK を使ってどうやればよいか、調べるのに時間かかったのでメモ。

LINEが公式で出している、 API Reference には、なかったので、ソースコードを読んだ。といっても TypeScript の型定義で事が足りた。

公式リファレンス https://line.github.io/line-bot-sdk-nodejs/pages/api-reference/client.html
ソースコード https://github.com/line/line-bot-sdk-nodejs/blob/b884dbaf0062429085a5ee6b830f526502ffab42/lib/types.ts#L383-L431

import { Client } from '@line/bot-sdk'

const message = {
  type: 'template',
  altText: 'エラーが発生しました。',
  template: {
    text,
    type: 'confirm',
    actions: [
      {
        type: 'message',
        label: 'はい',
        text: 'はい',
      },
      {
        type: 'message',
        label: 'いいえ',
        text: 'いいえ',
      },
    ],
  },
}

const client = new Client({
  channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN,
  channelSecret: process.env.LINE_CHANNEL_SECRET,
})

client.pushMessage('user_id', message)
0
1
1

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
1