def send_response()

in sample-code/python/main.py [0:0]


def send_response(reaction_type="valid reaction", machine_id="valid ID", data=""):
    # return False    # You will be replacing this function body with a working one
    print("Target Project ID: "+PROJECT_ID)
    print("Topic ID: "+TOPIC_ID)

    publisher = pubsub.PublisherClient()
    topic_path = f"projects/{PROJECT_ID}/topics/{TOPIC_ID}"

    message_data = json.dumps(data).encode("utf-8")
    message = {
        "data": message_data,
        "attributes": {
            "PinballReactionType": reaction_type,
            "MachineId": machine_id
        } 
    }

    try: 
        future = publisher.publish(topic_path, message['data'], **message['attributes'])
        message_id = future.result()
        print(f"Message {message_id} published successfully")
    except Exception as e:
        print(f"Error publishing message: {str(e)}")