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.
This commit is contained in:
Hemna 2021-07-15 20:34:51 -04:00
parent d983e1a824
commit 0a1d2b3e0e
3 changed files with 81 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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: <signing secret token here>
bot_token: <Bot User OAuth Access Token here>
channel: <channel name here>
"""
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 = "<http://aprs.fi/info/a/{}|{}>".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