from botocore.vendored import requests
import json

BOT_TOKEN = 'xoxb-*************-*************-************************'

def update(channel_id, message_ts, response):
    url = "<https://slack.com/api/chat.update>"
    headers = {
        "Content-type": "application/json; charset=utf-8",
        "Authorization": "Bearer " + BOT_TOKEN
    }
    data = {
        "channel": channel_id,
        "ts": message_ts,
        "blocks": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": ":checkered_flag:*책 제작 신청 응답*\\n\\n" + response["text"]
                }
            },
            {
                "type": "image",
                "image_url": response["img"],
                "alt_text": "response"
            }
        ]
    }

    response = requests.post(url, headers=headers, data=json.dumps(data))
    print(response)
    if response.json().get('ok'):
        print('메시지를 성공적으로 보냈습니다.\\n')
    else:
        print('메시지를 성공적으로 보내지 못했습니다. 오류메시지 : ' + str(response.json()))