1212@app .errorhandler (ValueError )
1313def handle_invalid_usage (e ):
1414 print (f'error: { e } ' )
15- response = jsonify ({'status_code' : 403 , 'message' : str (e )})
16- response .status_code = 403
17- return response
15+ return error (text = str (e ), status = 403 )
1816
1917
2018@app .route ('/' , methods = ['GET' , 'POST' ])
@@ -24,10 +22,10 @@ def home():
2422 image = _github_preview_image (),
2523 button1 = 'hello \U0001F44B ' ,
2624 post_url = url_for ('second_page' , _external = True ),
27- button2 = 'github ' ,
28- button2_action = 'link ' ,
29- button2_target = 'https://github.com/devinaconley/python-frames ' ,
30- button3 = 'do not press '
25+ button2 = 'do not press \U0001F6AB ' ,
26+ button3 = 'github ' ,
27+ button3_action = 'link ' ,
28+ button3_target = 'https://github.com/devinaconley/python-frames '
3129 )
3230
3331
@@ -37,19 +35,19 @@ def second_page():
3735 msg = message ()
3836 print (f'received frame message: { msg } ' )
3937
40- if msg . untrustedData . buttonIndex == 3 :
41- e = error ( 'wrong button!' )
42- print (e )
43- return e
38+ # check input
39+ if msg . untrustedData . buttonIndex == 2 :
40+ print ('invalid button input' )
41+ return error ( 'wrong button!' ) # popup message to user
4442
4543 # validate frame message with neynar
4644 api_key = os .getenv ('NEYNAR_KEY' )
4745 msg_neynar = validate_message_or_mock_neynar (msg , api_key , mock = _vercel_local ())
4846 print (f'validated frame message, fid: { msg_neynar .interactor .fid } , button: { msg_neynar .tapped_button } ' )
4947
50- # validate frame message with hub
51- msg_hub = validate_message_or_mock (msg , 'https://nemes.farcaster.xyz:2281' , mock = _vercel_local ())
52- print (f'validated frame message hub, fid: { msg_hub .data .fid } , button: { msg_hub .data .frameActionBody .buttonIndex } ' )
48+ # validate frame message with hub (alternative)
49+ # msg_hub = validate_message_or_mock(msg, 'https://nemes.farcaster.xyz:2281', mock=_vercel_local())
50+ # print(f'validated frame message hub, fid: {msg_hub.data.fid}, button: {msg_hub.data.frameActionBody.buttonIndex}')
5351
5452 return frame (
5553 image = _github_preview_image (),
0 commit comments