Skip to content

Retrieve client_id

osk2 edited this page Apr 10, 2021 · 1 revision

Retrieve Client ID

client_id is LINE user ID or group ID

Retrieve client_id can be tricky. We have to build a server to receive webhook request from LINE, and extract ID from it

We use Firebase Cloud Functions to reduce our pain

Create Firebase project

Create a Firebase project and enable Functions on sidebar

you may need to upgrade to Blaze plan which can cost your money, but don't worry there's free quota (2M/month)

Create Cloud Function Project

npm install -g firebase-tools

mkdir line-webhook-receiver
cd line-webhook-receiver

firebase init

# follow the instruction to complete setup

? What language would you like to use to write Cloud Functions? **JavaScript**
? Do you want to use ESLint to catch probable bugs and enforce style? **No**
? Do you want to install dependencies with npm now? **Yes**

Create function

# inside line-webhook-receiver
vim functions/index.js

replace content of index.js with:

const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
  const events = request.body.events
  const source = events.length > 0 ? events[0].source : null;

  if (source) {
    functions.logger.info(source.groupId || source.userId);
  }
  response.send("Hello from Firebase!");
});

Deploy function

firebase deploy

Enable LINE webhook

Go to https://developers.line.biz/console/channel/<CHANNEL ID>/messaging-api

image

Retrieve ID

Friend bot account or invite bot to your group chat

You should be able to see client_id in Cloud Functions log after sending some nice message to your bot

image

Disable LINE webhook again or your log will be flooded