Git Product home page Git Product logo

line-bot-for-render's Introduction

Line-bot-python-simple-starter

Python Line Flask Heroku

安裝所需要的外部模組

$ pip install line-bot-sdk flask pyquery

說明

本範例改寫於line-bot-sdk-python,較適合初次接觸聊天機器人架設的人使用,並適用於Heroku的架設環境。

檔案敘述

檔案名稱 功能
app.py Linebot主程式、Flask應用主程式
Procfile 成功上架至Heroku後的執行檔案,Heroku將會執行這個檔案內所寫的指令 python app.py來執行這主程式
requirements.txt 套件需求檔,所有使用到的外部套件需條列在此檔內,應用程式上架至Heroku後需透過此檔案替執行環境安裝所需套件
readme.md 本說明文件
.gitignore 條列不想要被git紀錄的檔案

初次建構的環境需求

需要透過此範例架設Line聊天機器人,必須準備好以下步驟

  1. 安裝line-bot-sdk請下pip install line-bot-sdk
  2. 安裝Git
  3. 註冊Heroku帳號並安裝Heroku CLI
  4. Line開發者帳號,並替你的機器人建立頻道
  5. 啟用Webhook並取得Channel Secret與Access Token
  6. 請將Channel Secret與Access Token寫入app.py文件指定的位置
  7. 上架應用程式至Heroku

1. 安裝Git

請至Git的官方網站下載並安裝Git

初次安裝好Git請透過終端機輸入以下指令:

git config --global user.name 你的使用者名稱
git config --global user.email 你的Email

2. 註冊Heroku帳號並安裝Heroku CLI

  1. Heroku官方網站註冊使用者帳號
  2. 下載Heroku CLI並安裝至電腦內
  3. 在終端機內輸入指令heroku login登入Heroku

2.1 在MacOS安裝Heroku CLI的選項

2.1.1 Standalone Installation with a Tarball
$ curl https://cli-assets.heroku.com/install.sh | sh
2.1.2 Install with npm
$ npm install -g heroku

3. 註冊Line開發者帳號,並替你的機器人建立頻道

  1. 前往Line開發者頁面點選Start using messaging API 並且使用LINE帳號登入
  2. 建立或選擇一個Provider
  3. 建立一個Channel並輸入相關資訊

4. 啟用Webhook並取得Channel Secret與Access Token

  1. 點選剛才建立的機器人帳號並進入編輯頁面
  2. 在編輯頁面中你可以找到頻道的Channel Secret,並產生一組Access Token
  3. 將Channel Secret與Access Token寫入app.py文件指定的位置內
  4. 點選Use webhooks並改寫成Enabled,將Webhook URL的對應網址改成 你的heroku專案名稱.herokuapp.com/callback

初次上架專案至Heroku

1. 建立一個Heroku專案

前往Heroku Dashboard並點選右上角的 new -> Create new app,建立一個專案。

2. 透過Git上架專案至Heroku

在專案資料夾內,開啟終端機並輸入以下指令:

git init
git add .
git commit -m "專案第一次上架"
heroku git:remote -a Heroku的專案名稱
git push heroku master

更新專案至Heroku

git add .
git commit -m "寫入你做的修改"
git push heroku master

line-bot-for-render's People

Contributors

hankamber avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.