Hey, I want to get the parent message in a slack thread using a thread id. I have never worked with API's but today I gave it a try. I got this code from chat gpt
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiErrordef main(input_data):
# Retrieve the Slack API token from the environment variables
SLACK_API_TOKEN = os.environ["SLACK_API_TOKEN"]# Initialize the WebClient with the API token
client = WebClient(token=SLACK_API_TOKEN)try:
# Call the conversations.history method using the WebClient
# The client passes the token you included in initialization
result = client.conversations_history(
channel=input_data["Thread_ID"],
inclusive=True,
oldest="1610144875.000600",
limit=1
)# Get the first message in the result
message = result["messages"][0]# Print the message text to the console
print(message["text"])except SlackApiError as e:
print(f"Error: {e}")
I used this python code found there but I got Traceback error, I also didn't know how to get the slack api token so didn’t add them there, could anyone tell me how to do them and what am doing wrong

Best answer by Troy Tessalone
View original