|
from flask import flask app = flask(__name__)
from flask import Flask, request, abort from linebot import LineBotApi, WebhookHandler from linebot.exceptions import InvalidSignatureError from linebot.models import (messageEvent, Textmessage, Textsendmessage)
line_bot_api = LineBotApi('+0J1zIUk8x3479Wx5OCCLGhVTWQA4GJf3dc40BzwNM5w16N9sgV2ptddhQFxQQHxc27hkYFF9Nhzo5hN81PYs3RhoVCKQIMfk5fA3cDSsISV1Tp/zOUl8RxEqEDGOspYJhwAqgErMop12YKj57HujwdB04t89/1O/w1cDnyilFU= Channel access token') handler = WebhookHandler('31a0430c094acfe0e63bc9940c584d9b channel secret')
@app.route("/callback",methods=['POST']) def callback(): signature = request.headers['X-Line-Signature'] body = request.get_data(as_text=True) try: hander.handle(body, signature) except InvalidSignatureError: abory(400) return 'ok' handler.add(MessageEvnt, message=Textmessage) def handle_message(event): line_bot_api,reply_message(event.reply_token, TextSendmessage(text=event.message.text) if __name__ =='__main__': app.run(debug = True,port=80) |