載入LineBot所需要的模組
from flask import Flask, request, abort
from linebot import (
LineBotApi, WebhookHandler
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import *
import re
from JOIN import *
app = Flask(__name__)
# 必須放上自己的Channel Access Token
line_bot_api = LineBotApi('h+x+HwN2YL3HZ9D7aZakdWgOu/HdbXhkScO5xwL2/bWMkGZz4w01LIbbnWuFCln43CdeRTPgQ1k9aWVz+1BNtRtSf5om4bFDR3GVfy7HEDcPxRoifwjE5jMCVAd3YJ9jZQOOY3IartfigcJPBxUfBAdB04t89/1O/w1cDnyilFU=')
# 必須放上自己的Channel Secret
handler = WebhookHandler('15cf868205ea07fce61a24c861ffa30c')
line_bot_api.push_message('Ua7db1f68375904c5158f3453ac21c2ef', TextSendMessage(text='你可以開始了'))
# 監聽所有來自 /callback 的 Post Request
@app.route("/callback", methods=['POST'])
def callback():
# get X-Line-Signature header value
signature = request.headers['X-Line-Signature']
# get request body as text
body = request.get_data(as_text=True)
app.logger.info("Request body: " + body)
# handle webhook body
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
#訊息傳遞區塊
##### 基本上程式編輯都在這個function #####
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
message =event.message.text
line_bot_api.reply_message(event.reply_token,TextSendMessage(message))
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
message = text = event.message.text
if re.match('加入',message):
flex_message = flex()
line_bot_api.reply_message(event.reply_token,flex_message)