Skip to content

Instantly share code, notes, and snippets.

@dtinth dtinth/index.ts
Created Oct 27, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.