Basically i want to loop through parent messages in a slack channel and fetch parent messages in front end but i also want to check if there are any replies under any parent message and fetch them under the parent message in front end. Bear in mind that there are two methods involved from slack, conversations.history and conversations.replies where conversations.replies requires the parameter of ts (timestamp). So what im trying to do is to check the timestamps of each message and if its found in conversations.replies then propagate the message or at least thats what im trying to do.
python:
@app.route("/", methods=['GET', 'POST'])
def home():
convo_history = client.conversations_history(channel=channel_to_listen)
messages = convo_history['messages']
for thread_ts in messages:
thread_reply = thread_ts['ts']
# app.logger.info(thread_reply)
convo_replies = client.conversations_replies(channel=channel_to_listen, ts=thread_reply)
# app.logger.info(convo_replies)
messages_replies = convo_replies['messages']
assert convo_history['ok']
return render_template('index.html', messages=messages, messages_replies=messages_replies)
Jinja:
{% for message in messages %}
{% if message['ts'] in messages_replies %}
<h2>{{ message['ts'] | ctime}}</h2>
<h3>{{ message['text'] }}</h3>
<h4>{{ messages_replies['text'] }}</h4>
{% else %}
<h2>{{ message['ts'] | ctime}}</h2>
<h3>{{ message['text'] }}</h3>
<br>
{% endif %}
{% endfor %}