Good evening, this is @ 0yan. Today, when I integrated the Flask app of the LINE WORKS version of Trello Bot into the Django app of the Bot that supports LINE WORKS inquiries, I was addicted to the difference in how to receive JSON data (Dasai ...). write.
You can receive it as a dictionary type value with data = request.json ['key']
.
Specific example (in the case of Flask)
@app.route('/webhook', methods=['HEAD', 'POST'])
def comment_notification_to_talk_room():
if request.method == 'HEAD':
return '', 200
elif request.method == 'POST':
action_type = request.json['action']['display']['translationKey'] #β
Coco
if action_type == 'action_comment_on_card':
card_name = request.json['action']['data']['card']['name']
user_name = request.json['action']['memberCreator']['fullName']
comment = request.json['action']['data']['text']
message = f'{user_name}Commented.\n [card]{card_name}\n [Comment]{comment}'
talk_bot.send_text_message(send_text=message)
return '', 200
else:
abort(400)
You need to convert from JSON to dictionary type, like body = json.loads (request.body)
.
Specific example (for Django)
def comment_notification_to_talk_room(request, bot_no, account_id=None, room_id=None):
talk_bot = TalkBotApi(api_id, server_api_consumer_key, server_id, private_key, domain_id, bot_no)
#Convert request body from JSON to dictionary type, action_Extract type
body = json.loads(request.body) #β
Coco
action_type = body['action']['display']['translationKey']
#Send Trello's comments to the LINE WORKS talk room
if action_type == 'action_comment_on_card':
card_name = body['action']['data']['card']['name']
user_name = body['action']['memberCreator']['fullName']
comment = body['action']['data']['text']
message = f'{user_name}Commented.\n [card]{card_name}\n [Comment]{comment}'
if account_id is not None:
talk_bot.send_text_message(send_text=message, account_id=account_id)
logger.info(f'Notification success accountID:{account_id}')
elif room_id is not None:
talk_bot.send_text_message(send_text=message, room_id=room_id)
logger.info(f'Notification successful roomID:{room_id}')
else:
logger.error('accoutId,You need to specify either roomId.')
No, I would spend a few hours doing such a silly thing ... I hope this failure helps someone.
Recommended Posts