Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Slack Replies by allowing use of thread_timestamp #1033

Merged
merged 5 commits into from Dec 29, 2023

Conversation

AlexScotland
Copy link
Contributor

@AlexScotland AlexScotland commented Dec 28, 2023

Description:

This enhancement allows Slack notification plugin to accept timestamps of messages that it should reply too.

This allows Apprise to reply into multiple channel's messages, creating a chat thread for relevant notifications.

Syntax

Thread Timestamp (defined as {thread_ts} below can be added to defined elements using a colon : delimiter like so:

  • slack://{tokenA}/{tokenB}/{tokenC}/#{channel}:{thread_ts}
  • slack://{tokenA}/{tokenB}/{tokenC}/#{channel1}:{thread_ts}/#{channel2}:{thread_ts}/#{channelN}:{thread_ts}
  • slack://{botname}@{tokenA}/{tokenB}/{tokenC}/+{encoded_id}:{thread_ts}
  • slack://{botname}@{tokenA}/{tokenB}/{tokenC}/+{encoded_id1}:{thread_ts}/+{encoded_id2}:{thread_ts}/+{encoded_id3}:{thread_ts}
  • slack://{botname}@{tokenA}/{tokenB}/{tokenC}/@{user_id}:{thread_ts}
  • slack://{botname}@{tokenA}/{tokenB}/{tokenC}/@{user_id1}:{thread_ts}/@{user_id2}:{thread_ts}/@{user_id3}:{thread_ts}

New Service Completion Status

Not Applicable

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@<this.branch-name>

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  slack://slack_bot_oauth/#channel1:timestamp1/channel2:timestamp2

… we will make it so that every channel can independently have a thread to reply too

adds default value for ts_thread, fixing testcases

removes print
apprise/plugins/NotifySlack.py Outdated Show resolved Hide resolved
test/test_plugin_slack.py Outdated Show resolved Hide resolved
test/test_plugin_slack.py Outdated Show resolved Hide resolved
@AlexScotland AlexScotland marked this pull request as draft December 28, 2023 20:36
@AlexScotland AlexScotland marked this pull request as ready for review December 28, 2023 20:37
adds changes from PR

removes Walrus Operator for Dockerbuild compatibility
@AlexScotland
Copy link
Contributor Author

pushed changes for Walrus operator removal, as it was conflicting with the Docker build.

@codecov-commenter
Copy link

codecov-commenter commented Dec 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c47de7f) 99.27% compared to head (92bde91) 99.27%.
Report is 4 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1033      +/-   ##
==========================================
- Coverage   99.27%   99.27%   -0.01%     
==========================================
  Files         136      135       -1     
  Lines       17669    17563     -106     
  Branches     3603     3585      -18     
==========================================
- Hits        17541    17435     -106     
  Misses        119      119              
  Partials        9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@caronc
Copy link
Owner

caronc commented Dec 28, 2023

That was fast! I'll review tomorrow 🚀🙂

@caronc
Copy link
Owner

caronc commented Dec 29, 2023

I pushed a few changes to your code to handle some edge cases. Can you have a git pull in your branch and just double-check it's working okay for you?

Also, i'm curious if you could share/provide steps on how one can get the timestamp from Slack so that they can provide it into Apprise. Is it in the URL, or something they can copy and paste out of the message thread?

@caronc caronc changed the title Slack Replies Enhancement Support Slack Replies by allowing use of thread_timestamp Dec 29, 2023
@AlexScotland
Copy link
Contributor Author

I pushed a few changes to your code to handle some edge cases. Can you have a git pull in your branch and just double-check it's working okay for you?

Also, i'm curious if you could share/provide steps on how one can get the timestamp from Slack so that they can provide it into Apprise. Is it in the URL, or something they can copy and paste out of the message thread?

Just double checked, and seems the Regular expression is not matching on the CHANNEL_RE.search(channel) (line 568)

to answer your question, the slack api gives back a ts attribute on message send, which is the timestamp of the message. Some external storage tool could provide Apprise this data to send a thread.

It is also accessible on the slack frontend with some inspect element - slack uses the timestamp as the div's ID attribute

@AlexScotland
Copy link
Contributor Author

Pushed a change to the regex that suits the naming schema a bit better - please verify if any adjustments are needed :)

@caronc caronc merged commit bb4acd0 into caronc:master Dec 29, 2023
12 checks passed
@caronc
Copy link
Owner

caronc commented Dec 29, 2023

Looks good! Great work! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants