|
20 | 20 | import tempfile
|
21 | 21 | from argparse import ArgumentParser
|
22 | 22 |
|
23 |
| -from flask import Flask, request, abort |
| 23 | +from flask import Flask, request, abort, send_from_directory |
| 24 | +from werkzeug.middleware.proxy_fix import ProxyFix |
24 | 25 |
|
25 | 26 | from linebot import (
|
26 | 27 | LineBotApi, WebhookHandler
|
|
41 | 42 | UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent,
|
42 | 43 | FlexSendMessage, BubbleContainer, ImageComponent, BoxComponent,
|
43 | 44 | TextComponent, SpacerComponent, IconComponent, ButtonComponent,
|
44 |
| - SeparatorComponent, QuickReply, QuickReplyButton |
45 |
| -) |
| 45 | + SeparatorComponent, QuickReply, QuickReplyButton, |
| 46 | + ImageSendMessage) |
46 | 47 |
|
47 | 48 | app = Flask(__name__)
|
| 49 | +app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_host=1, x_proto=1) |
48 | 50 |
|
49 | 51 | # get channel_secret and channel_access_token from your environment variable
|
50 | 52 | channel_secret = os.getenv('LINE_CHANNEL_SECRET', None)
|
@@ -126,6 +128,13 @@ def handle_text_message(event):
|
126 | 128 | line_bot_api.reply_message(
|
127 | 129 | event.reply_token,
|
128 | 130 | TextSendMessage(text="Bot can't leave from 1:1 chat"))
|
| 131 | + elif text == 'image': |
| 132 | + url = request.url_root + '/static/logo.png' |
| 133 | + app.logger.info("url=" + url) |
| 134 | + line_bot_api.reply_message( |
| 135 | + event.reply_token, |
| 136 | + ImageSendMessage(url, url) |
| 137 | + ) |
129 | 138 | elif text == 'confirm':
|
130 | 139 | confirm_template = ConfirmTemplate(text='Do it?', actions=[
|
131 | 140 | MessageAction(label='Yes', text='Yes!'),
|
@@ -427,6 +436,11 @@ def handle_beacon(event):
|
427 | 436 | event.beacon.hwid, event.beacon.dm)))
|
428 | 437 |
|
429 | 438 |
|
| 439 | +@app.route('/static/<path:path>') |
| 440 | +def send_static_content(path): |
| 441 | + return send_from_directory('static', path) |
| 442 | + |
| 443 | + |
430 | 444 | if __name__ == "__main__":
|
431 | 445 | arg_parser = ArgumentParser(
|
432 | 446 | usage='Usage: python ' + __file__ + ' [--port <port>] [--help]'
|
|
0 commit comments