From bf41c581d9a268f48ee0b9709901971bbc2336cb Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 13 Aug 2026 09:51:16 -0400 Subject: [PATCH] Initial Commit --- Gemfile | 1 + LICENSE | 21 ++++++ README.md | 79 +++++++++++++++++++++++ init.rb | 22 +++++++ lib/redmine_send_dm.rb | 16 +++++ lib/redmine_send_dm/hooks/msg_listener.rb | 54 ++++++++++++++++ 6 files changed, 193 insertions(+) create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.rb create mode 100644 lib/redmine_send_dm.rb create mode 100644 lib/redmine_send_dm/hooks/msg_listener.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..42b1964 --- /dev/null +++ b/Gemfile @@ -0,0 +1 @@ +gem "sentdm" \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6ca2371 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2026 Rick Barrette + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c42e2d4 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# Redmine Send.dm + +A Send.dm plugin for Redmine to allow messages to be sent via SMS. + +--- + +## Features + +* Provides a custom hook (`:send_sms`) that other plugins can call to send SMS messages with dynamic template parameters. + +--- + +## Prerequisites + +* **Redmine:** `5.0.0` or higher (Fully tested on `7.0.0`) +* **Ruby:** `3.2+` +* **Gem:** `sentdm` +* **API Key:** `SENT_DM_API_KEY` set in your environment variables + +--- + +## Installation + +1. Ensure the `sentdm` gem is included in your Redmine environment: + + ```bash + bundle add sentdm + ``` + +2. Clone or copy the plugin into your Redmine `plugins` directory: + + ```bash + cd /path/to/redmine/plugins + git clone https://github.com/rickbarrette/redmine_send_dm.git + ``` + +3. Run database migrations (if applicable): + + ```bash + bundle exec rake redmine:plugins:migrate RAILS_ENV=production + ``` + +4. Restart your Redmine application instance: + + * **Standard deployment:** `touch tmp/restart.txt` + * **Docker deployment:** `docker compose restart redmine` + +--- + +## Usage / Hook Trigger + +In your caller plugin, invoke the `:send_sms` hook passing the recipient phone number and dynamic template parameters: + +```ruby +phone = "123-456-7890" + +# Construct the dynamic parameters hash matching your Sent.dm template fields +template_params = { + date: format_date(appointment.date), + code: "123456" +} + +# Dispatch hook with phone number and parameter payload +Redmine::Hook.call_hook(:send_sms, phone: phone, parameters: template_params) +``` + +--- + +## License + +> The MIT License (MIT) +> +> Copyright (c) 2026 Rick Barrette +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..79072a3 --- /dev/null +++ b/init.rb @@ -0,0 +1,22 @@ +#The MIT License (MIT) +# +#Copyright (c) 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Redmine::Plugin.register :redmine_send_dm do + name 'Redmine send.dm Plugin' + author 'Rick Barrette' + description 'Provids SMS capability via send.dm' + version '2026.8.0' + url 'https://github.com/rickbarrette/redmine_send_dm' + author_url 'https://github.com/rickbarrette' + + # Require the core scheduler runner logic + requires_redmine version_or_higher: '5.0.0' +end + +RedmineSendDm.setup \ No newline at end of file diff --git a/lib/redmine_send_dm.rb b/lib/redmine_send_dm.rb new file mode 100644 index 0000000..952f519 --- /dev/null +++ b/lib/redmine_send_dm.rb @@ -0,0 +1,16 @@ +#The MIT License (MIT) +# +#Copyright (c) 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +module RedmineSendDm + def self.setup + # Hooks + RedmineSendDm::Hooks::MsgListener + end +end \ No newline at end of file diff --git a/lib/redmine_send_dm/hooks/msg_listener.rb b/lib/redmine_send_dm/hooks/msg_listener.rb new file mode 100644 index 0000000..8609dac --- /dev/null +++ b/lib/redmine_send_dm/hooks/msg_listener.rb @@ -0,0 +1,54 @@ +#The MIT License (MIT) +# +#Copyright (c) 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +require "sentdm" + +module RedmineSendDm + module Hooks + class MsgListener < Redmine::Hook::Listener + + def send_sms(context = {}) + phone = context[:phone] + # Dynamically read parameters passed from caller hook + parameters = context[:parameters] || context[:msg] || {} + + # Sanitize phone number to keep digits only + clean_phone = phone.to_s.gsub(/\D/, '') + + sent_dm = Sentdm::Client.new + + begin + result = sent_dm.messages.send_( + to: ["+1#{clean_phone}"], + template: { + id: "103f89ec-672b-4fc8-a703-9958f181fa77", + parameters: parameters + }, + channel: ["sms"] + ) + + if result&.data&.recipients&.any? + log "Message ID: #{result.data.recipients[0].message_id}" + log "Status: #{result.data.status}" + end + + rescue StandardError => e + log "Error sending SMS: #{e.message}" + end + end + + private + + def log(msg) + Rails.logger.info "[MsgListener] #{msg}" + end + end + end +end \ No newline at end of file