Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- 認証情報
AccessToken = 'Bearer ???=' -- ???に自分のChannel Access Token 変更箇所1
-- 受信メッセージから送信メッセージを構築
body = json.parse(request.body)
reply = body.events[1].replyToken -- 返信先
inBoxMessage = body.events[1].message.text -- 受信メッセージ
-- 返答パターン
-- resTable['ここに書いたキーワードがLINEで入力されると'] = 'これが返されます'
resTable = {}
resTable['こんにちは'] = 'Hello!'
resTable['ありがとう'] = 'Thank you!'
resTable['こんばんは'] = 'Good evening!!'
for key,value in pairs(resTable) do
if (string.find(inBoxMessage, key)) then
res = value
end
end
-- どの返答パターンにもマッチしなかったら
-- "ここをランダムで返信します",
if (not res) then
t = {"Yo! Yo!",
"OK!",
"My name is yoshiki!"
}
i = math.random(#t)
res = t[i]
end
data = {
['replyToken'] = reply,
['messages'] = {{
['type'] = 'text',
['text'] = res
}}
}
-- メッセージ送信
local response = http.request {
url = 'https://api.line.me/v2/bot/message/reply',
method = 'POST',
data = json.stringify(data),
headers = {
['Content-Type'] = 'application/json; charser=UTF-8',
['Authorization'] = AccessToken
}
}
return 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.