-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a web hook for the line bot, and pass testing data for now. ### Related Issue - #87
- Loading branch information
Showing
5 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Client, TextMessage } from '@line/bot-sdk'; | ||
|
||
import { config } from 'lib/config' | ||
// set Channel Access Token and Channel Secret for Line Bot | ||
const client = new Client({ | ||
channelAccessToken: config.line.LINE_ACCESS_TOKEN || '', | ||
channelSecret: config.line.LINE_CHANNEL_SECRET, | ||
}); | ||
|
||
// @todo: pass rent data from api. | ||
const message: TextMessage = { | ||
type: 'text', | ||
text: 'Zuzugo got a new house!', | ||
}; | ||
|
||
// @todo: get groupId from database. | ||
export default async function sendLineBotMessage(groupId: string) { | ||
await client.pushMessage(groupId, message) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { WebhookEvent, User, Group, Room } from "@line/bot-sdk"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import sendLineBotMessage from 'lib/notification/lineBot' | ||
|
||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
|
||
if (req.method !== "POST") { | ||
res.status(405).json({ error: "Sorry! This endpoint does not accept your requests." }); | ||
return; | ||
} | ||
|
||
const events: WebhookEvent[] = req.body.events; | ||
const [firstEvent] = events; | ||
|
||
if (firstEvent.type === 'join') { | ||
const { | ||
userId = '', | ||
groupId = '', | ||
roomId = '', | ||
// @todo: save chatType to database. | ||
// type: chatType, | ||
} = firstEvent.source as User & Group & Room; | ||
|
||
const chatId = userId || groupId || roomId; | ||
try { | ||
await sendLineBotMessage(chatId) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
res.send(200) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16f0aba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
zuzugo – ./
zuzugo.vercel.app
zuzugo-git-main-yukaihuangtw.vercel.app
zuzugo-yukaihuangtw.vercel.app