Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Create LINE Bot with Elixir

Create LINE Bot with Elixir

Introduce my own LINE Bot created with Elixir and that's features.
tokyo.ex #2 LT Slide #beamlangtokyo
http://beam-lang.connpass.com/event/30513/

Takayuki Matsubara

May 23, 2016
Tweet

More Decks by Takayuki Matsubara

Other Decks in Programming

Transcript

  1. Create LINE Bot with
    Elixir

    View Slide

  2. self-introduction
    me
    |> name # Takayuki Matsubara
    |> job # Software Engineer
    |> work_at # M3, Inc.
    |> works # Rails, Java, JavaScript
    |> twitter # ma2ge
    |> github # ma2gedev
    |> oss # PowerAssertEx, breadcrumble,
    # chrono_logger, bundle-star,
    # faraday-encoding

    View Slide

  3. My LINE Bot(Not Public)

    View Slide

  4. Structure
    4 Phoenix Framework
    4 HTTPoison
    4 PostgreSQL

    View Slide

  5. Features

    View Slide

  6. Help

    View Slide

  7. Run Elixir code from
    LINE app

    View Slide

  8. Implementation
    {result, bindings} = Code.eval_string(
    code, [], [file: "linebot.ex", line: 1]
    )
    4 [WIP] takeover session
    4 [WIP] security

    View Slide

  9. Pitfall !

    View Slide

  10. Train information

    View Slide

  11. 4 https://twitter.com/twcrone/status/
    574623119618535425/photo/1

    View Slide

  12. Implementation - Worker
    defmodule ZakuHead.PeriodicTask do
    use GenServer
    def start_link do
    GenServer.start_link(__MODULE__, %{})
    end
    def init(state) do
    Process.send_after(self(), :work, 0) # start immediately when starting
    {:ok, state}
    end
    def handle_info(:work, state) do
    # scraping from the train information page
    # find some trouble routes and notify LINE BOT API
    Process.send_after(self(), :work, 5 * 60 * 1000) # every 5 minutes
    {:noreply, state}
    end
    end

    View Slide

  13. Implementation - Scraping
    4 Floki
    4 https://github.com/philss/floki

    View Slide

  14. jobs.m3.com/engineer/

    View Slide

  15. Start/Stop Zaku

    View Slide

  16. View Slide

  17. View Slide

  18. See Also if you interested in cloudBit
    4 https://speakerdeck.com/ma2gedev/playing-with-
    littlebits-number-m3dev

    View Slide

  19. Light Sensor

    View Slide

  20. View Slide

  21. Resources
    4 LINE BOT API
    4 https://developers.line.me/bot-api/overview

    View Slide