Try   HackMD

國軍回報 Line bot

contributed by <yanjiun>

Github

https://github.com/yanjiuntw/ninja-hattori

  1. 沒有 github 帳號可能需要申請一個。
  2. Fork 這個專案到自己帳號內。
  3. 有兩個檔案需要修改:
    • index.js 需要填上自己的資料庫(後面會申請)
      ​​​​​​​​...
      ​​​​​​​​  .connect(
      ​​​​​​​​    '請輸入資料庫網址(mongo)',
      ​​​​​​​​    { useNewUrlParser: true }
      ​​​​​​​​  )
      ​​​​​​​​...
      
    • bot.config.js 需要修改自己的 LINE 機器人資料(後面會申請)
      ​​​​​​  ...
      ​​​​​​  channelId: '請輸入',
      ​​​​​​  channelSecret: '請輸入',
      ​​​​​​  channelAccessToken: '請輸入',
      ​​​​​​  ...
      

MongoDB Atlas

https://www.mongodb.com/cloud/atlas

  1. 沒有 MongoDB Atlas 帳號可能需要申請一個。

  2. 建一個新專案create project

  3. 建立叢集build cluster,選擇 Shared Clusters 可以免費試用。

    • 可免費建立一個僅 512M 的資料庫試用(M0 Sandbox)
    • 可選擇資料庫想存放在哪個組織與國家(會影響速度,距離愈遠愈慢),其餘不用特別設定,點選create cluster
    • 完成後會像以下圖片。
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  4. 新增資料庫帳號與密碼。

  5. 點選 connect 後選擇 connect your applaction,點選 copy 並貼到自己 Github 專案內的 index.js中。並修改貼上文字中的<password> 為剛剛設定的密碼,再修改 <dbname> 為自己想要的資料庫名稱。

  6. 完成後類似這樣

...
.connect(
    'mongodb+srv://test:U0PA9tAz5vV5k6Xz@cluster0.aslrj.mongodb.net/test?retryWrites=true&w=majority',
    { useNewUrlParser: true }
  )
...

Line Developr

https://developers.line.biz/en/

  1. 沒有 Line 帳號可能需要申請一個。
  2. 建立 Providers
  3. 建立 Channel,選擇 Messaging API 並完成後續資料填寫。
  4. 這裡獲得 bot.config.js 所需要的三個東西,將其複製到檔案中。
    • channelIdchannelSecret 可以在 Basic setting 下方可以找到
    • channelAccessToken 在 Messaging API 最下面,需點選 issue 才會產生。
  5. 後面再回來設定剩餘的東西。

Heroku

https://dashboard.heroku.com

  1. 沒有 Heroku 帳號可能需要申請一個。
  2. 點選 New -> Create new app,並完成建立。
  3. deploy 頁面下,選擇 Github 並登入,完成後輸入專案名稱並搜尋,找到後點 connect
  4. 點選下方 deploy branch 並稍待片刻,完成後會看到綠色打勾。
  5. setting 頁面下,複製 domain 後方網址(LINE 要用)

Line bot

到剛剛 Line Developr 網頁

  1. 在 Messaging API 下方找到 Webhook settings ,將剛剛 Heroku app 的網址貼上。
  2. Allow bot to join group chats 打開
  3. 將其餘不需要功能關閉

References