This boilerplate project shows how to use Line Notify API with firebase functions. The client side is a super simple react app which only has a button to call firebase functions.
- Node.js v12 installed
- Firebase CLI installed
Generate access token for Line Notify Api. This article will help.
The app expects the access token through firebase functions config. You should set the access token like this:
firebase functions:config:set line_notify.token=YOUR_TOKEN_COMES_HERE
If you want to test the functionality in dev env, set the access token in functions/.runtimeconfig.json
(which is used by firebase functions emulator) like this:
{
"line_notify": {
"token": "YOUR TOKEN COMES HERE"
}
}
Make sure you only take this approach in dev env or some sucure manner. You DO NOT push token to public repo.
Before you run dev server, follow the steps below to set up your firebase project with this boilerplate app.
- Update
.firebaserc
Find your project id and replace the value of project.default
inside .firebaserc
with your project id like this:
{
"projects": {
"default": "your-project-id"
}
}
- Update firebase config in
/src/lib/firebase.ts
Get your firebase prject config object and replace firebaseConfig object with yours.
//TODO: repalce with your firebase config
const firebaseConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
};
Now you're ready to test out !
Install dependencies for both ./
project and ./functions
by running npm install.
npm install && npm --prefix ./functions install
Run the command below and startup firebase functions emulator and react dev server.
yarn dev
Access http://localhost:3000 and push the button to send a message to line.
(You need to set access token in .runtimeconfig.json
to test in dev env. Please refer to Prepare Line Notify API Token section.)