Notifcations are ways to deliver the results of Questions to users without going through the normal Metabase UI. At the time of this writing, there are two delivery mechanisms for Notifications -- email and Slack notifications; these destinations are known as 'Channels'. Notifications themselves are futher divied into two categories -- 'Pulses', which are sent at specified intervals, and 'Alerts', which are sent when certain conditions are met (such as a query returning results).
Because 'Pulses' were originally the only type of Notification, this name is still used for the model itself, and in some of the functions below. To keep things clear try to make sure you use the term 'Notification' for things that work with either type.
One more thing to keep in mind: this code is pretty old and doesn't follow the code patterns used in the other Metabase models. There is a plethora of CRUD functions for working with Pulses that IMO aren't really needed (e.g. functions for fetching a specific Pulse). At some point in the future, we can clean this namespace up and bring the code in line with the rest of the codebase, but for the time being, it probably makes sense to follow the existing patterns in this namespace rather than further confuse things.
Notifcations are ways to deliver the results of Questions to users without going through the normal Metabase UI. At the time of this writing, there are two delivery mechanisms for Notifications -- email and Slack notifications; these destinations are known as 'Channels'. Notifications themselves are futher divied into two categories -- 'Pulses', which are sent at specified intervals, and 'Alerts', which are sent when certain conditions are met (such as a query returning results). Because 'Pulses' were originally the only type of Notification, this name is still used for the model itself, and in some of the functions below. To keep things clear try to make sure you use the term 'Notification' for things that work with either type. One more thing to keep in mind: this code is pretty old and doesn't follow the code patterns used in the other Metabase models. There is a plethora of CRUD functions for working with Pulses that IMO aren't really needed (e.g. functions for fetching a specific Pulse). At some point in the future, we can clean this namespace up and bring the code in line with the rest of the codebase, but for the time being, it probably makes sense to follow the existing patterns in this namespace rather than further confuse things.
Schema for valid values of :alert_condition
for Alerts.
Schema for valid values of `:alert_condition` for Alerts.
(card->ref card)
Inputs: [card :- su/Map] Returns: CardRef
Create a card reference from a card or id
Inputs: [card :- su/Map] Returns: CardRef Create a card reference from a card or id
Schema for the map we use to internally represent the fact that a Card is in a Notification and the details about its presence there.
Schema for the map we use to internally represent the fact that a Card is in a Notification and the details about its presence there.
(cards notification-or-id)
Inputs: [notification-or-id] Returns: [HybridPulseCard]
Return the Cards associated with this notification
.
Inputs: [notification-or-id] Returns: [HybridPulseCard] Return the Cards associated with this `notification`.
(channels notification-or-id)
Return the PulseChannels associated with this notification
.
Return the PulseChannels associated with this `notification`.
Schema for functions accepting either a HybridPulseCard
or CardRef
.
Schema for functions accepting either a `HybridPulseCard` or `CardRef`.
(create-alert! alert creator-id card-id channels)
Creates a pulse with the correct fields specified for an alert
Creates a pulse with the correct fields specified for an alert
(create-pulse! cards channels kvs)
Inputs: [cards :- [#:s{Keyword s/Any}] channels :- [#:s{Keyword s/Any}] kvs :- {:name su/NonBlankString, :creator_id su/IntGreaterThanZero, (s/optional-key :skip_if_empty) (s/maybe s/Bool), (s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero)}]
Create a new Pulse by inserting it into the database along with all associated pieces of data such as: PulseCards, PulseChannels, and PulseChannelRecipients.
Returns the newly created Pulse, or throws an Exception.
Inputs: [cards :- [#:s{Keyword s/Any}] channels :- [#:s{Keyword s/Any}] kvs :- {:name su/NonBlankString, :creator_id su/IntGreaterThanZero, (s/optional-key :skip_if_empty) (s/maybe s/Bool), (s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero)}] Create a new Pulse by inserting it into the database along with all associated pieces of data such as: PulseCards, PulseChannels, and PulseChannelRecipients. Returns the newly created Pulse, or throws an Exception.
This schema represents the cards that are included in a pulse. This is the data from the PulseCard
and some
additional information used by the UI to display it from Card
. This is a superset of CardRef
and is coercible to
a CardRef
This schema represents the cards that are included in a pulse. This is the data from the `PulseCard` and some additional information used by the UI to display it from `Card`. This is a superset of `CardRef` and is coercible to a `CardRef`
(Pulse)
(Pulse id)
(Pulse & kvs)
Entity for 'pulse' table; instance of PulseInstance.
Entity for 'pulse' table; instance of PulseInstance.
(retrieve-alert alert-or-id)
Inputs: [alert-or-id] Returns: (s/maybe PulseInstance)
Fetch a single Alert by its id
value, do the standard hydrations, and put it in the standard Alert
format.
Inputs: [alert-or-id] Returns: (s/maybe PulseInstance) Fetch a single Alert by its `id` value, do the standard hydrations, and put it in the standard `Alert` format.
(retrieve-alerts)
(retrieve-alerts {:keys [archived?] :or {archived? false}})
Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance]
Fetch all Alerts.
Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance] Fetch all Alerts.
(retrieve-alerts-for-cards & card-ids)
Find all alerts for CARD-IDS
, used for admin users
Find all alerts for `CARD-IDS`, used for admin users
(retrieve-notification notification-or-id & additional-condtions)
Inputs: [notification-or-id & additional-condtions] Returns: (s/maybe PulseInstance)
Fetch an Alert or Pulse, and do the 'standard' hydrations.
Inputs: [notification-or-id & additional-condtions] Returns: (s/maybe PulseInstance) Fetch an Alert or Pulse, and do the 'standard' hydrations.
(retrieve-pulse pulse-or-id)
Inputs: [pulse-or-id] Returns: (s/maybe PulseInstance)
Fetch a single Pulse, and hydrate it with a set of 'standard' hydrations; remove Alert coulmns, since this is a Pulse and they will all be unset.
Inputs: [pulse-or-id] Returns: (s/maybe PulseInstance) Fetch a single *Pulse*, and hydrate it with a set of 'standard' hydrations; remove Alert coulmns, since this is a *Pulse* and they will all be unset.
(retrieve-pulses)
(retrieve-pulses {:keys [archived?] :or {archived? false}})
Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance]
Fetch all Pulses
.
Inputs: ([] [{:keys [archived?], :or {archived? false}}]) Returns: [PulseInstance] Fetch all `Pulses`.
(retrieve-user-alerts-for-card card-id user-id)
Find all alerts for card-id
that user-id
is set to receive
Find all alerts for `card-id` that `user-id` is set to receive
(unsubscribe-from-alert! alert-id user-id)
Unsubscribe a User with user-id
from an Alert with alert-id
.
Unsubscribe a User with `user-id` from an Alert with `alert-id`.
(update-alert! alert)
Updates the given ALERT
and returns it
Updates the given `ALERT` and returns it
(update-notification! notification)
Inputs: [notification :- {(s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :skip_if_empty) s/Bool, (s/optional-key :alert_first_only) s/Bool, (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero), (s/optional-key :channels) [su/Map], (s/optional-key :name) su/NonBlankString, (s/optional-key :cards) [CoercibleToCardRef], :id su/IntGreaterThanZero, (s/optional-key :alert_above_goal) s/Bool, (s/optional-key :alert_condition) AlertConditions, (s/optional-key :archived) s/Bool}]
Update the supplied keys in a notification
.
Inputs: [notification :- {(s/optional-key :collection_id) (s/maybe su/IntGreaterThanZero), (s/optional-key :skip_if_empty) s/Bool, (s/optional-key :alert_first_only) s/Bool, (s/optional-key :collection_position) (s/maybe su/IntGreaterThanZero), (s/optional-key :channels) [su/Map], (s/optional-key :name) su/NonBlankString, (s/optional-key :cards) [CoercibleToCardRef], :id su/IntGreaterThanZero, (s/optional-key :alert_above_goal) s/Bool, (s/optional-key :alert_condition) AlertConditions, (s/optional-key :archived) s/Bool}] Update the supplied keys in a `notification`.
(update-notification-cards! notification-or-id card-refs)
Inputs: [notification-or-id card-refs :- (s/maybe [CardRef])]
Update the PulseCards for a given notification-or-id
.
card-refs
should be a definitive collection of all Cards for the Notification in the desired order. They should
have keys like id
, include_csv
, and include_xls
.
card-refs
has no corresponding existing PulseCard
object, one will be created.PulseCard
has no corresponding ID in CARD-IDs, it will be deleted.position
according to their place in the collection of card-ids
Inputs: [notification-or-id card-refs :- (s/maybe [CardRef])] Update the PulseCards for a given `notification-or-id`. `card-refs` should be a definitive collection of *all* Cards for the Notification in the desired order. They should have keys like `id`, `include_csv`, and `include_xls`. * If a Card ID in `card-refs` has no corresponding existing `PulseCard` object, one will be created. * If an existing `PulseCard` has no corresponding ID in CARD-IDs, it will be deleted. * All cards will be updated with a `position` according to their place in the collection of `card-ids`
(update-notification-channels! notification-or-id channels)
Inputs: [notification-or-id channels :- [su/Map]]
Update the PulseChannels for a given notification-or-id
.
CHANNELS should be a definitive collection of all of the channels for the the pulse.
PulseChannel
object, one will be created.PulseChannel
has no corresponding entry in CHANNELS, it will be deleted.Inputs: [notification-or-id channels :- [su/Map]] Update the PulseChannels for a given `notification-or-id`. CHANNELS should be a definitive collection of *all* of the channels for the the pulse. * If a channel in the list has no existing `PulseChannel` object, one will be created. * If an existing `PulseChannel` has no corresponding entry in CHANNELS, it will be deleted. * All previously existing channels will be updated with their most recent information.
(update-pulse! pulse)
Inputs: [pulse]
Update an existing Pulse, including all associated data such as: PulseCards, PulseChannels, and PulseChannelRecipients.
Returns the updated Pulse or throws an Exception.
Inputs: [pulse] Update an existing Pulse, including all associated data such as: PulseCards, PulseChannels, and PulseChannelRecipients. Returns the updated Pulse or throws an Exception.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close