Closed irrational-labs closed 1 year ago
Hi @irrational-labs ,
Are you able to provide more information around these retries?
Information like timestamps, or request IDs (if you set your app to provide debug level logging, you should be able to see this information). Does the bot post the same say
message? I.e. is it following the same branch through your if
/elif
chain? Also, are you sure no other message or post to the relevant thread has triggered the event again?
Hey @filmaj, I am not able to provide more info about these re-tries. If it's not too much to ask, could you provide documentation about how to set up debug-level logging? I just un-commented out a "print(event)" command under the elif statement that's triggering multiple times, so I'll reply if there are any weird payloads there after a dupe is sent. The bot does say the same "say" message that it said earlier. I'm positive no other message or post triggered it, the post will happen when there have been no new messages in the channel.
I saw this response from a similar issue saying to remove and re-add the bot from the channel. I also realized printing events more that I wasn't filtering out events with a 'subtype' so I'm wondering if the bot was triggering responses when someone edited or deleted a message. I'll let you know if these changes work! https://github.com/microsoft/botframework-sdk/issues/3614
If it's not too much to ask, could you provide documentation about how to set up debug-level logging?
Check out our documentation on logging; something like the following near the top of your app code should do it:
import logging
logging.basicConfig(level=logging.DEBUG)
I also realized printing events more that I wasn't filtering out events with a 'subtype' so I'm wondering if the bot was triggering responses when someone edited or deleted a message.
Ooooh this is a great theory! Definitely have a look at the available message subtypes, and, if there is a particular subtype that you could constrain your message event listener to, then that would limit the potential for getting seemingly-duplicate events that may be, sneakily, not actually duplicates. Check out our documentation on listening to events, and in particular, expand "Filtering on message subtypes" section in that documentation link. Related, if you enable debug logging (or, as you've done before, simply print out a dictionary representation of the full event payload), you should be able to inspect the subtype
property on the event payload to see if maybe this property differs across these 'duplicate' events you are seeing.
Thanks so much @filmaj! I will add logging now. Really appreciate all of your help 🙏 I'll keep you updated on what happens.
Hey @irrational-labs, another way to handle only new messages would be:
@app.event({"type": "message", "subtype": (None, "bot_message", "thread_broadcast", "file_share")})
This is the same with the way @app.message
listeners receive only new messages: https://github.com/slackapi/bolt-python/blob/v1.15.5/slack_bolt/app/app.py#L771-L786
Amazing, thank you @seratch! I'm astounded by how awesome the community in this repository is. I believe I fixed the issue and am going to close the ticket. @filmaj it does seem that filtering out deleted and edited messages (i did this by filtering out any event that contained 'subtype' in it) stopped the dupe issue. Really appreciate all of your help :)
Glad to hear!
(Filling out the following details about bugs will help us solve your issue sooner.)
Reproducible in:
The
slack_bolt
versionslack-sdk==3.19.5 slack-bolt==1.15.5
(Paste the output of
pip freeze | grep slack
)Python runtime version
3.9.12 (Paste the output of
python --version
)OS info
ProductName: macOS ProductVersion: 12.6.1 BuildVersion: 21G217 Darwin Kernel Version 21.6.0: Thu Sep 29 20:12:57 PDT 2022; root:xnu-8020.240.7~1/RELEASE_X86_64
(Paste the output of
sw_vers && uname -v
on macOS/Linux orver
on Windows OS)Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
Initializes your app with your bot token and signing secret
app = App( token=os.environ["SLACK_BOT_TOKEN"] )
autoreply in hw function
@app.event("message") def auto_reply(event, say): try: if 'files' in event: #need to handle events with attachments differently if event['channel'] == "C019J946UPJ" and ('.pdf' in event['files'][0]['name'] or '.google' in event['text']) and (event['user'] != 'U038JV06ZMZ' and event['user'] != 'U03612ME0BY' and event['user'] != 'U029XD01PNF' and event['user'] != 'U038JV0HD19' and event['user'] != 'U03E7JSK3LG'): #if statement clarifying channel to watch for & to not reply to replies say(text = "An IL scientist will connect with you shortly. Before we do, take this opportunity to double check your key behavior. Is it uncomfortably specific? See the examples in this document to help you refine your thinking. https://docs.google.com/document/d/1EVoyhVnX_jTzNbWBrN8C9Bz8-A7xHO8wN5dM6o-Oves/edit#", thread_ts = event['ts'])
print(event)