1

I am developing a WhatsApp bot that allows users to send multiple images at once and perform operations accordingly. I am using WATI API

The user responses are received on the server in one go, and it takes a few seconds to update the URL in the Airable cell via Airtable Web API.

As a result, only the if condition is executed, causing overwriting of the existing cell value instead of appending the new image URLs to it.

@app.route('/kc', methods=['POST', 'GET'])
def execute():
    data = request.json
    senderID = data['waId']
    name = data['senderName']
    # print(data)

    if data['type'] == 'image':
        new_image_url = data.get('data')
        print("URL received ", new_image_url)

        id, existing_image_url = at.get_field(senderID, "image_fetched")
        print(id, existing_image_url)
        if existing_image_url is None:
                existing_image_url = ""


        image_urls = existing_image_url.split("\n")

    # Append the new URL to the list
        image_urls.append(new_image_url)

    # Join the URLs back into a string with newline character separator
        image_array = "\n".join(image_urls)

        print(image_array)
        at.update_image_url(id, image_array)


    return data

Output on terminal: enter image description here

Only the last link is stored

enter image description here

How can I modify my code to ensure that the new image URLs are appended to the existing URLs in the Airtable cell, even if the responses are received in one go and there is a delay in updating the URL in the backend?

Dummy Cron
  • 143
  • 2
  • 11

0 Answers0