From 0a1d2b3e0e6fb8e75d8ca2ccc4d3f88cf769bceb Mon Sep 17 00:00:00 2001 From: Hemna Date: Thu, 15 Jul 2021 20:34:51 -0400 Subject: [PATCH] Update for new plugin interface. Add Notify plugin This patch adds the notify plugin to be used with the new notification plugins interface for aprsd. This sends a notification to a slack channel when a HAM callsign is seen on the APRS-IS network after a specified timeout/age. --- aprsd_slack_plugin/base_plugin.py | 3 +- aprsd_slack_plugin/location_plugin.py | 5 +- aprsd_slack_plugin/notify_plugin.py | 76 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 aprsd_slack_plugin/notify_plugin.py diff --git a/aprsd_slack_plugin/base_plugin.py b/aprsd_slack_plugin/base_plugin.py index 71434a5..84328ea 100644 --- a/aprsd_slack_plugin/base_plugin.py +++ b/aprsd_slack_plugin/base_plugin.py @@ -1,6 +1,5 @@ import logging -from aprsd import plugin from aprsd import utils as aprsd_utils from slack_sdk import WebClient @@ -9,7 +8,7 @@ import aprsd_slack_plugin LOG = logging.getLogger("APRSD") -class SlackPluginBase(plugin.APRSDPluginBase): +class SlackPluginBase: """SlackCommandPlugin. This APRSD plugin looks for the location command comming in diff --git a/aprsd_slack_plugin/location_plugin.py b/aprsd_slack_plugin/location_plugin.py index cce3c20..13a0ca5 100644 --- a/aprsd_slack_plugin/location_plugin.py +++ b/aprsd_slack_plugin/location_plugin.py @@ -48,9 +48,12 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase): command_regex = "^[lL]" command_name = "location-slack" - def command(self, fromcall, message, ack): + def command(self, packet): LOG.info("SlackCommandPlugin") + fromcall = packet["from"] + message = packet["message_text"] + is_setup = self.setup_slack() if not is_setup: return diff --git a/aprsd_slack_plugin/notify_plugin.py b/aprsd_slack_plugin/notify_plugin.py new file mode 100644 index 0000000..39c33bc --- /dev/null +++ b/aprsd_slack_plugin/notify_plugin.py @@ -0,0 +1,76 @@ +import logging + +from aprsd import messaging, plugin + +import aprsd_slack_plugin +from aprsd_slack_plugin import base_plugin + +LOG = logging.getLogger("APRSD") + + +class SlackNotifyPlugin( + base_plugin.SlackPluginBase, + plugin.APRSDNotificationPluginBase, +): + """SlackCommandPlugin. + + This APRSD plugin looks for the location command comming in + to aprsd, then fetches the caller's location, and then reports + that location string to the configured slack channel. + + To use this: + Create a slack bot for your workspace at api.slack.com. + A good source of information on how to create the app + and the tokens and permissions and install the app in your + workspace is here: + + https://api.slack.com/start/building/bolt-python + + + You will need the signing secret from the + Basic Information -> App Credentials form. + You will also need the Bot User OAuth Access Token from + OAuth & Permissions -> OAuth Tokens for Your Team -> + Bot User OAuth Access Token. + + Install the app/bot into your workspace. + + Edit your ~/.config/aprsd/aprsd.yml and add the section + slack: + signing_secret: + bot_token: + channel: + """ + + version = aprsd_slack_plugin.__version__ + + def notify(self, packet): + LOG.info("SlackCommandPlugin") + + fromcall = packet["from"] + # message = packet["message_text"] + + is_setup = self.setup_slack() + if not is_setup: + return + + # get last location of a callsign, get descriptive name from weather service + + callsign_url = "".format(fromcall, fromcall) + + message = {} + message["username"] = "APRSD - Slack Notification Plugin" + message["icon_emoji"] = ":satellite_antenna:" + message["attachments"] = [{}] + message["text"] = "{} - Is now on APRS".format(callsign_url) + message["channel"] = "#hemna" + + LOG.debug(message) + + # self.swc.chat_postMessage(**message) + for channel in self.slack_channels: + message["channel"] = channel + self.swc.chat_postMessage(**message) + + # Don't have aprsd try and send a reply + return messaging.NULL_MESSAGE