line bot sample

by gustavex

GitHub Readme.md

What is it?

A simple example of Looker Action Hub to send a message to your LINE bot. (LINE is one of the major messaging platforms in Japan.)

Looker Action Hub References

How to deploy

  1. Line Business to get a LINE Business account
  2. Heroku to deploy Action Hub Server
  3. Setting on your Looker instance
    • Register your Action Hub in the Admin panel
    • Embed action in the LookML

1. Line ID

  1. Register your new LINE Business Account

  2. Log in to the Developer console with your LINE Business Account

  3. Set up a Messenger API Channel along with this procedure

  4. You can manage your channel at Console. Keep Channel access token (long-lived) and Your user ID

  5. Read a bot QR code QR code of your bot and add to your LINE friend

2. Deploy your Action Hub Server on Heroku

  1. Access to Heroku, if you don't have heroku account, create one from Screen Shot 2019-11-15 at 21.29.32.png
  2. Deploy this sample application to your heroku by clicking Deploy to deploy your Heroku. Names your application
  3. Set your application vars at Settings > Reveal Config Vars

Screen Shot 2019-11-15 at 21.56.41.png

  1. Enter your Channel access token (long-lived) and Your user ID as an environment variable. Var names should be CHANNEL_ACCESS_TOKEN, LINE_USER_ID

Screen Shot 2019-11-15 at 22.02.57.png

3. Looker Set Up

  1. Access to https://{your_looker_instance}/admin/actions and set up your Action Hub Server, click Screen Shot 2019-11-15 at 22.06.08.png button
  2. Enter as https://{your_heroku_app_name}.herokuapp.com/action_list and click Add Action Hub

Screen Shot 2019-11-15 at 22.07.35.png

7. Click `Enable` and `Save`

Screen Shot 2019-11-15 at 22.10.41.png

Screen Shot 2019-11-15 at 22.11.45.png

8. Edit a dimension like:
dimension: name {
  type: string
  sql: ${TABLE}.name ;;
  action: {
    label: "Send to LINE"
    url: "https://{your_app_name}.herokuapp.com/action_execute"
    icon_url: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMQEBAQEBESEhITERIQEBARDQ8SExUVFhEWFhUSFRUYHSggGR0lGxUTIT0hJSsrLi4uFyA4ODMsNyktLisBCgoKDg0OGxAQGC0lHyYuMC4rLS0uLS0tNS8tLy8tMC8tLy0tLS0tLS0tLS0vLS8tL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VEnPtjDWl2u/YjRm6Q7KR70bP0n2Y497mlSvJznJznLXKc5OUm+LZW2vNp2yqbXm07Zl6Hh5AAAAAAAAAAAAuBI/4TPcSPw9kn8NdnOPC8liq0epydSPZPne1tdw1VNzLaPf5msx7ma0e/zRpHRQAAAAAAAAAAAAPh0le9lcyztl9hgMAAAAAAAAAAAAAHvgsM6tSnTXy5KPc3rfquz3jpv2ive2YqekvFO9avvaPmr1HS7le51e5Xuc5nxkzTpxrxXOpq0+ML7e5+DZA6Qw71fSR2c/D+ld0np96vpI5xz8P6cMU6hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOtzFyZeUsTJaleFLi9kpd2zvZZ9H4ds+kn3LfovT7Z9LPhH1+ztC2XbEldWetPU0wc1e5zZAeHk6lNN0W+3Qb+S+G5/wBuj1elnFO9Xq/Jzmt0c4Z3q9X5IAhIAAAAAAAAAAAAAAAAAAAAAAAAAAAErkDIs8VPrjST58//AJjvfs9snTaa2a3s7ZStJpLZ7f8Az2z/ALtWTQoxpxjCCUYxSUUupIvq1isbI5OmpWKViteUPQ9PQBicU000mmrNNXTW5oxMbeEsTETGyXJZYzOTvPDNRe3kpN6P0ZdXY/Arc/R8Txx+So1HRcT+rFOz2fZyuMydVov8rTlDi1eP7y1FbfFenWjYqcmDJj69Zj/d7Vua2oAAAAAAAAAAAAAAAAAAAAAA98Lg6lV2pQlP0YtrvexHumO1+rG17x4r5OpEy6bJOZsm1LEuy/2oO7fCUuru9ZYYej5njk8lrp+i5njln3R9/t5uxoUY04qEIqMUrKKVki0rWKxsiOC5rStI3axsh6Hp6AAAAB8z2MxLE8lcZx9NlFqus5vW9ZDERBAAAAAAAAAAAAAAAAAAAAkci+URI0/WSdL11mYXoR7EX9OrDp6dWHqensAAAP/Z"
    form_param: {
      name: "message"
      type: textarea
      required: yes
      default: "Thank you!!"
    }
  }
}
  1. Open an Explore and run query, you can find an action in the cell. Click Send to LINE

Screen Shot 2019-11-16 at 9.23.22.png

  1. Input some messages and click Submit

Screen Shot 2019-11-16 at 9.24.47.png

11. If you got a message, success!

IMG_1898.PNG

Above is an example of cell level action. You can create an action as a query level as well. If query level action is created, you can send LINE from the top of the gear icon in the Explore or Look. Screen Shot 2019-11-16 at 9.27.08.png