Giter Club home page Giter Club logo

hubot-line-message-api's Introduction

hubot-line-message-api

設定

必須

  • 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に設定してあげてください。

できること

今のところpushで送信は対応できておらず、返信しかできません。

  • 返信

    • Text

    https://devdocs.line.me/ja/#text

    module.exports = (robot) ->
        robot.hear /^テキスト$/, (res) ->
            res.reply
                type: 'text'
                contents: ['nyaa']
    • Image or Video

    https://devdocs.line.me/ja/#image https://devdocs.line.me/ja/#video

    module.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'
                ]
    • Button

    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/'
                    ]
                ]
    • Confirm

    https://devdocs.line.me/ja/#confirm

    module.exports = (robot) ->
        robot.hear /^コンファーム$/, (res) ->
            res.reply
                type: 'confirm'
                altText: 'hogehoge'
                contents: [
                    text: 'confirm description'
                    actions:{
                        type: 'message'
                        label: 'Yes'
                        text: 'yes'
                    },{
                        type: 'message'
                        label: 'No'
                        text: 'no'
                    }
                ]
    • Carousel

    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 Carousel'
                    text: 'carousel description'
                    actions:[
                        type: 'uri'
                        label: 'Open in Browser'
                        uri: 'http://example.com/'
                    ],
                    image: 'https://example.com/images/image.jpg'
                    title: 'this is Carousel'
                    text: 'carousel 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/'
                    ]
                ]
            }
  • コンテンツ受信

    • イメージ受信
    {ImageMessage} = require 'hubot-line-message-api'
    
    robot.hear /.*/, (res) ->
        if res.message instanceof ImageMessage
            res.message.getContent (content) ->
                fs.writeFile 'sample.jpg', content, 'binary'
  • Postback(ユーザのボタン押下など)

     {PostbackMessage} = require 'hubot-line-message-api'
    
     robot.hear /.*/, (res) ->
         if res.message instanceof PostbackMessage
             # postback.data
             console.log(res.message.data)

注意点

  • contents.length <= 5にしないとLINEに怒られます。
    • くみあわせて使う場合はcontents.lengthを足し算した値が5を超えないようにしないと怒られます。
  • 画像のURLなどはhttpsでないと怒られます。

Special Thanks

@shouta-dev Thank you for your contibutions!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.