hubot-line-message-apiをつくった
BOT API Trial Account廃止
新しいMessaging APIが登場してしばらくたちましたが、とうとう既存のBOT API Trial Accountが廃止されます。
Messaging API のリリースとBOT API Trial Account廃止のご案内
旧API トライアルアカウント「BOT API Trial Account」をお使いの皆さまには、新しいトライアルアカウント「Developer Trial」のご利用をお願い致します。
だそうです。
新しいトライアルアカウントはこちらからどうぞ。
今までとは違うところ
LINE Messaging API が BOT API から変わったところ。 - Qiita
を見ていただければ分かる通り、送受信のJSONがかわります。
hubotでつくっとったbotはどうなるんや・・・
hubot-line-trialを使ってhubotからlinebotに通知させてみた - Qiitaの記事をかいた@tochi_ondyさんが作っていただいたアダプターなどが使えなくなっているので、せっかくなので自分で作ってみました。
hubot-line-message-api
- 基本的にherokuで公開するコトを想定して作っています。これらを設定してあげてください。
- LINE_CHANNEL_ACCESS_TOKEN
- LINEアカウントのBasic Infomationにある
Channel Access Token
の値を設定してください。
- HUBOT_ENDPOINT
- defaultで/hubot/incomingになってます。
- 自由に設定していただいて大丈夫です。
- FIXIE_URL
- herokuで走らす場合は必須かなと思います。
-
Fixieというアドオンを使います。
-
$ heroku addons:create fixie:tricycle
を叩くと自動で設定されています。
- 出力されるIPアドレスを
Server IP Whitelist
に設定してあげてください。
- Yeomanでつくると楽です
- adapterに
line-message-api
を指定してください
- LINE_CHANNEL_ACCESS_TOKEN
- LINEアカウントのBasic Infomationにある
Channel Access Token
の値を設定してください。
- LINEアカウントのBasic Infomationにある
- HUBOT_ENDPOINT
- defaultで/hubot/incomingになってます。
- 自由に設定していただいて大丈夫です。
- FIXIE_URL
- herokuで走らす場合は必須かなと思います。
- Fixieというアドオンを使います。
-
$ heroku addons:create fixie:tricycle
を叩くと自動で設定されています。 - 出力されるIPアドレスを
Server IP Whitelist
に設定してあげてください。
- adapterに
line-message-api
を指定してください
ここらへんはググるとすぐ出てくると思います。
つかいかた
まずダウンロード
$ git clone https://github.com/pyonk/hubot-line-message-api.git
yoで作ってください
package.jsonにローカルのものを登録します
"dependencies": {
"line-message-api": "file:./hubot-line-message-api"
}
できること
今のところpushで送信は対応できておらず、返信しかできません。
-
返信
- テキスト
https://devdocs.line.me/ja/#text
module.exports = (robot) -> robot.hear /^テキスト$/, (res) -> res.reply type: 'text' contents: ['nyaa']
- 画像と動画
https://devdocs.line.me/ja/#image
https://devdocs.line.me/ja/#videomodule.exports = (robot) -> robot.hear /^画像$/, (res) -> res.reply type:'image'# 'video' content: [ original: 'https://example.com/images/image.jpg' preview: 'https://example.com/images/image.jpg' ]
- ボタン
https://devdocs.line.me/ja/#buttons
module.exports = (robot) -> robot.hear /^テキスト$/, (res) -> res.reply type: 'buttons' altText: 'hogehoge' contents: [ image: 'https://example.com/images/image.jpg' title: 'this is Buttons' text: 'buttons description' actions:[ type: 'uri' label: 'Open in Browser' uri: 'http://example.com/' ] ]
- カルーセル
https://devdocs.line.me/ja/#carousel
module.exports = (robot) -> robot.hear /^カルーセル$/, (res) -> res.reply type: 'carousel' altText: 'hogehoge' contents: [ image: 'https://example.com/images/image.jpg' title: 'this is Buttons' text: 'buttons description' actions:[ type: 'uri' label: 'Open in Browser' uri: 'http://example.com/' ], image: 'https://example.com/images/image.jpg' title: 'this is Buttons' text: 'buttons description' actions:[ type: 'uri' label: 'Open in Browser' uri: 'http://example.com/' ]... ]
- くみあわせ
module.exports = (robot) -> robot.hear /^くみあわせ$/, (res) -> res.reply { type: 'text' contents: ['nyaa'] }, { type: 'buttons' contents: [ image: 'https://example.com/images/image.jpg' title: 'this is Buttons' text: 'buttons description' actions: [ type: 'uri' label: 'Open in Browser' uri: 'http://example.com/' ] ] }
注意点
-
contents.length <= 5
にしないとLINEに怒られます。
- くみあわせて使う場合はcontents.lengthを足し算した値が5を超えないようにしないと怒られます。
- 画像のURLなどはhttpsでないと怒られます。
最後に
contents.length <= 5
にしないとLINEに怒られます。
- くみあわせて使う場合はcontents.lengthを足し算した値が5を超えないようにしないと怒られます。
APIのリファレンス読んでおけば問題ないとおもいます。
初めてcoffeescriptをちゃんと触って、アダプターも初めて書きました。
至らない点もあるかと思いますので、教えていただくと幸いです。
まだ機能的に十分ではないので、暇を見て機能追加していきます。
ソースコードはこちらです。
Author And Source
この問題について(hubot-line-message-apiをつくった), 我々は、より多くの情報をここで見つけました https://qiita.com/pyonk/items/f276e6fd71ff63fed88f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .