Skip to content

louis70109/Announcer

Repository files navigation

Announcer Backend (AB) 🔈

License: MIT

AB would provide Flex Message template and LINE bot feature.

  • Type any text to trigger bot for send Announcer template.
  • About GA feature, please follow this article.

Add friends

加入好友

QRcode

Environment

  • Express / nodejs v12.18
  • TypeScript

Heroku

You can test this project on Heroku.

Deploy

Use following up commands to check machine:

heroku run bash -a YOUR_HEROKU_NAME
heroku logs --tail -a YOUR_HEROKU_NAME

LIFF

  • Login LINE Developer Console.
  • Create a LINE Login channel.
  • Input channel information.
  • Click LIFF tab and add LIFF application.
  • Copy LIFF ID to environment CONCAT_ID variable.

Messaging API

  • Login LINE Developer Console.
  • Create a Messaging API channel.
  • Input channel information.
  • Copy Channel secret and Channel access token to environment CHANNEL_ACCESS_TOKEN and CHANNEL_SECRET variables.

Local test with Chatbot & API

1. first terminal window

cp .env.sample .env
npm install
npm run dev

2. Create a provisional https:

npx ngrok http 5000

3. Copy url to Messaging API and LIFF endpoint url.

LINE Bot

You can go to LINE Developer Console to change LINE Bot webhook url.

If you used channel_access_toen and channel_secret in .env file.

You can use change_bot_url.sh to change temp webhook url.

sh change_bot_url.sh 57G...YOUR_ACCESS_TOKEN...vw= https://{YOUR_DOMAIN}/webhooks/line

will see following log:

--------------------------

{}

--------------------------

{"endpoint":"https://{YOUR_DOMAIN}/webhooks/line","active":true}
-------------------------
  • {}: if empty, means success.

4. Use following command before deploy:

npm run dev

This command will compile TypeScript to JavaScript file in dist/.

5. Local Unit/Integration Test

If you use .env to develop this project(contain LINE Bot token), can use following command:

npm run test
  • If you installed act locally, run act to check GitHub Actions status.

Template Schema

API ➡️ /liff/share

Template 1 - Announcement

type announcement = {
    template: '1',
    title: 'Title',
    place: 'location',
    time: '12/26 15:00',
    url: 'HTTP string',
    imageUrl: 'HTTP string',
    description: 'aaa\nbbb\nccc',
    activity: 'some tag',
};

Template 2 - Staff List

type staffList = {
  template: '2',
  title: 'title',
  place: 'here',
  url: 'HTTP link',
  activity: 'tag',
  map: 'Google Map link',
  people: [{name: 'NiJia', time: '10:00~12:00'}],
};

Template 3 - Card

type Card = {
  template: '2',
  title: 'title',
  description: 'aaa\nbbb',
  avatar: 'HTTP link',
  back: 'HTTP image background link',
  followUrl: 'HTTP link',
};

Template 4 - News

type News = {
  image: string;
  date: string;
  description: string;
  link: string;
  tag: string;
  targetPicker?: string;
}

Response

Above template would response following type:

type FlexResponse = {
  flex: string;
};

License

MIT License