LINE Bot 作ってみた
ひげ
Abstruct: LINE Bot を作った
ScoreBot : CTF のスコアボードを Bot で
メッセージとしてフラグを送信
自分のスコアや問題を出力
SDK: Go 言語
Heroku + PostgreSQL
IBM Bluemix + AWS RDS
フレームワークを意識した設計
を話そうと思ってた
しかし
普通だ...
変態エンジニアが多い(要出典)
ドリコムでこんな普通の話をするの
か...
そこで
LINE Bot 作ってみた
ひげ
Haskell で
LINE Bot 作ってみた
ひげ
Abstruct: LINE Bot を作った
ScoreBot : CTF のスコアボードを Bot で
Curry-Howard 同型対応を返す Bot
論文の参照付き!
SDK: Go 言語 Haskell
Heroku + Postgress
IBM Bluemix + AWS RDS
フレームワークを意識した設計
完全にネタ
GitHub に
matsubara0507/curry-howard-linebot
友達登録
  
Curry-Howard Bot    Score Bot (ついで)
依存ライブラリ
Haskell SDK for LINE Messaging API
github.com/noraesae/line
Haskell Web Application Interface
github.com/yesodweb/wai
Heroku buildpack for Haskell Stack
github.com/mfine/heroku-buildpack-stack
Demo
データベースの代わりに...
curryHowardCorrespondence :: [([Text], [Text], URL)]
curryHowardCorrespondence =
[ ( ["Natural Deducation", "自然演繹"]
, ["Typed Lambda Calclus", "型付きラムダ計算"]
, "http://disi.unitn.it/.../Papers/curry-howard.pdf")
, ( ["Sequent Calculus", "シーケント計算"]
, ["Typed Lambda Calclus", "型付きラムダ計算"]
, "http://disi.unitn.it/.../Papers/curry-howard.pdf")
, ( ["System F"]
, ["Polymorphic Lambda Calculus", "2階ラムダ計算"]
, "http://disi.unitn.it/.../Papers/curry-howard.pdf")
, ( ["Modal Logic", "様相論理"]
, ["Mondad", "モナド"]
, "http://www.sciencedirect.com/.../S0304397596001697")
]
Get Correspondence
getCorrespondence :: Text -> Text
getCorrespondence = fromMaybe "unknown..." . lookupCorrespondence
lookupCorrespondence :: Text -> Maybe Text
lookupCorrespondence txt =
msum $ fmap match curryHowardCorrespondence
where
match (xs, ys, url)
| txt `elem` xs = appendUrl url <$> safeHead ys
| txt `elem` ys = appendUrl url <$> safeHead xs
| otherwise = Nothing
appendUrl :: URL -> Text -> Text
appendUrl url = unwords . (: [url])
safeHead :: [a] -> Maybe a
safeHead = find (const True)
Event Handler
サンプルコードの1つ目の echo の引数をかえただけ
handleMessageEvent :: ReplyableEvent EventMessage -> IO ()
handleMessageEvent event = do
case getMessage event of
TextEM _ (Text text) ->
echo (getReplyToken event) (getCorrespondence text)
_ -> echo (getReplyToken event) "undefined message"
api :: APIIO a -> IO (Either APIError a)
api = runAPI getChannelToken
echo :: ReplyToken -> T.Text -> IO ()
echo replyToken content = do
api $ reply replyToken [ Message . Text $ content ]
return ()
おしまい

Haskell で LINE Bot を作ってみた

  • 1.
  • 2.
    Abstruct: LINE Botを作った ScoreBot : CTF のスコアボードを Bot で メッセージとしてフラグを送信 自分のスコアや問題を出力 SDK: Go 言語 Heroku + PostgreSQL IBM Bluemix + AWS RDS フレームワークを意識した設計 を話そうと思ってた
  • 3.
  • 4.
  • 5.
  • 6.
  • 8.
  • 9.
    Haskell で LINE Bot作ってみた ひげ
  • 10.
    Abstruct: LINE Botを作った ScoreBot : CTF のスコアボードを Bot で Curry-Howard 同型対応を返す Bot 論文の参照付き! SDK: Go 言語 Haskell Heroku + Postgress IBM Bluemix + AWS RDS フレームワークを意識した設計 完全にネタ
  • 11.
  • 12.
  • 13.
    依存ライブラリ Haskell SDK forLINE Messaging API github.com/noraesae/line Haskell Web Application Interface github.com/yesodweb/wai Heroku buildpack for Haskell Stack github.com/mfine/heroku-buildpack-stack
  • 14.
  • 15.
    データベースの代わりに... curryHowardCorrespondence :: [([Text],[Text], URL)] curryHowardCorrespondence = [ ( ["Natural Deducation", "自然演繹"] , ["Typed Lambda Calclus", "型付きラムダ計算"] , "http://disi.unitn.it/.../Papers/curry-howard.pdf") , ( ["Sequent Calculus", "シーケント計算"] , ["Typed Lambda Calclus", "型付きラムダ計算"] , "http://disi.unitn.it/.../Papers/curry-howard.pdf") , ( ["System F"] , ["Polymorphic Lambda Calculus", "2階ラムダ計算"] , "http://disi.unitn.it/.../Papers/curry-howard.pdf") , ( ["Modal Logic", "様相論理"] , ["Mondad", "モナド"] , "http://www.sciencedirect.com/.../S0304397596001697") ]
  • 16.
    Get Correspondence getCorrespondence ::Text -> Text getCorrespondence = fromMaybe "unknown..." . lookupCorrespondence lookupCorrespondence :: Text -> Maybe Text lookupCorrespondence txt = msum $ fmap match curryHowardCorrespondence where match (xs, ys, url) | txt `elem` xs = appendUrl url <$> safeHead ys | txt `elem` ys = appendUrl url <$> safeHead xs | otherwise = Nothing appendUrl :: URL -> Text -> Text appendUrl url = unwords . (: [url]) safeHead :: [a] -> Maybe a safeHead = find (const True)
  • 17.
    Event Handler サンプルコードの1つ目の echoの引数をかえただけ handleMessageEvent :: ReplyableEvent EventMessage -> IO () handleMessageEvent event = do case getMessage event of TextEM _ (Text text) -> echo (getReplyToken event) (getCorrespondence text) _ -> echo (getReplyToken event) "undefined message" api :: APIIO a -> IO (Either APIError a) api = runAPI getChannelToken echo :: ReplyToken -> T.Text -> IO () echo replyToken content = do api $ reply replyToken [ Message . Text $ content ] return ()
  • 18.