Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created October 27, 2018 20:24
Show Gist options
  • Save dtinth/579025fbbb1e5a66ad72e291daceadc0 to your computer and use it in GitHub Desktop.
Save dtinth/579025fbbb1e5a66ad72e291daceadc0 to your computer and use it in GitHub Desktop.
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