Skip to content

Commit

Permalink
retrieve message function change
Browse files Browse the repository at this point in the history
  • Loading branch information
zibiax committed Apr 23, 2024
1 parent 5652483 commit 762a402
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions test_draftgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ def retrieve_slack_message(channel_id, slack_token):
headers = {
"Authorization": f"Bearer {slack_token}",
}
# Construct the API URL with the channel ID
API_URL = f"https://slack.com/api/conversations.history?token={slack_token}&channel={channel_id}&limit=1&inclusive=true"
# Construct the request data
data = {
"channel": channel_id,
"limit": 1,
"inclusive": True
}
# Construct the API URL
API_URL = "https://slack.com/api/conversations.history"
print("API URL:", API_URL) # Print the constructed API URL
response = requests.get(API_URL, headers=headers)
print("Response:", response) # Print the response object
response = requests.get(API_URL, headers=headers, params=data)
try:
response_json = response.json()
print("Response JSON:", response_json) # Print the JSON response
# Extract the text of the first message
message_text = response_json["messages"][0]["text"]
return message_text
except Exception as e:
print("Error:", e) # Print any exceptions that occur
print("Error: No messages found in response.", response_json)
return ""
# Check if the response is successful
if response_json["ok"]:
# Extract the text of the first message
message_text = response_json["messages"][0]["text"]
return message_text
else:
print("Error:", response_json["error"])
return None
except (KeyError, IndexError):
print("Error: No messages found in response.")
return None


def draft_gpt(user_input, openai_api_key=os.environ["OPENAI_API_KEY"], gpt_model=os.environ["GPT_MODEL"]):
Expand Down

0 comments on commit 762a402

Please sign in to comment.