--- title: 國軍回報 Line bot tags: mynote --- # 國軍回報 Line bot contributed by <[`yanjiun`](https://github.com/yanjiunhaha)> ## Github https://github.com/yanjiuntw/ninja-hattori 1. 沒有 github 帳號可能需要申請一個。 2. Fork 這個專案到自己帳號內。 3. 有兩個檔案需要修改: * `index.js` 需要填上自己的資料庫(後面會申請) ```javascript ... .connect( '請輸入資料庫網址(mongo)', { useNewUrlParser: true } ) ... ``` * `bot.config.js` 需要修改自己的 LINE 機器人資料(後面會申請) ```javascript ... 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`。 * 完成後會像以下圖片。  5. 新增資料庫帳號與密碼。 6. 點選 `connect` 後選擇 `connect your applaction`,點選 `copy` 並貼到自己 Github 專案內的 `index.js`中。並修改貼上文字中的`<password>` 為剛剛設定的密碼,再修改 `<dbname>` 為自己想要的資料庫名稱。 7. 完成後類似這樣 ```javascript ... .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` 所需要的三個東西,將其複製到檔案中。 * `channelId` 與 `channelSecret` 可以在 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 * [ Github: billju/ninja-hattori ](https://github.com/billju/ninja-hattori)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up