From b6777746e4357afc12916cdc3cf09cc55e0ecdb9 Mon Sep 17 00:00:00 2001 From: James Coleman Date: Thu, 5 Oct 2023 19:32:19 -0500 Subject: [PATCH] Fix topic set after channel creation --- update.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/update.go b/update.go index ab14447..7c1406e 100644 --- a/update.go +++ b/update.go @@ -437,17 +437,22 @@ func CreateSlackChannels() { // If topic is defined, set the topic and purpose. if topic != "" { - // Sleep before, as it takes time for Slack APIs - // to recongize the channel was created. - time.Sleep(120 * time.Second) - _, err = app.slack.SetTopicOfConversation(channel.ID, topic) + // Keep count of failures so we can try again. + failed := 0 + _, err = app.slack.SetTopicOfConversation(schan.ID, topic) if err != nil { + failed++ log.Println("Failed to set topic:", err) } - _, err = app.slack.SetPurposeOfConversation(channel.ID, topic) + _, err = app.slack.SetPurposeOfConversation(schan.ID, topic) if err != nil { + failed++ log.Println("Failed to set purpose:", err) } + // If it failed, make topic empty so we can try again next run. + if failed != 0 { + topic = "" + } } // Save the channel to the database.