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 full-size 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 full-size slide

  3. My LINE Bot(Not Public)

    View full-size slide

  4. Structure
    4 Phoenix Framework
    4 HTTPoison
    4 PostgreSQL

    View full-size slide

  5. Run Elixir code from
    LINE app

    View full-size slide

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

    View full-size slide

  7. Train information

    View full-size slide

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

    View full-size slide

  9. 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 full-size slide

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

    View full-size slide

  11. jobs.m3.com/engineer/

    View full-size slide

  12. Start/Stop Zaku

    View full-size slide

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

    View full-size slide

  14. Light Sensor

    View full-size slide

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

    View full-size slide