Created
October 27, 2018 20:24
-
-
Save dtinth/579025fbbb1e5a66ad72e291daceadc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from 'firebase-functions' | |
import * as admin from 'firebase-admin' | |
import 'firebase-functions' | |
import express from 'express' | |
import { middleware, Client } from '@line/bot-sdk' | |
admin.initializeApp() | |
export const bot = functions.https.onRequest((req, res) => { | |
const config = { | |
channelAccessToken: functions.config().line.channel.accesstoken, | |
channelSecret: functions.config().line.channel.secret | |
} | |
middleware(config)(req, res, err => { | |
if (err) { | |
console.error('LINE bot middleware error:', err) | |
res.status(500).send('LINE bot middleware error') | |
return | |
} | |
const client = new Client(config) | |
for (const event of req.body.events) { | |
if (event.type === 'message') { | |
client.replyMessage(event.replyToken, [{ type: 'text', text: 'meow' }]) | |
} | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment