Set Up User-specified Alerts
You can set up Appkit to provide user-specified email alerts in an app.
Setup
To set up user-specified alerts:
-
Add this dependency to your
pom.xml
. Remove any previous reference totwigkit.social
modules.<dependency> <groupId>twigkit</groupId> <artifactId>twigkit.social.runtime</artifactId> <version>${project.parent.version}</version> </dependency> <dependency> <groupId>twigkit</groupId> <artifactId>twigkit.alert.db.derby.memory</artifactId> <version>${project.parent.version}</version> </dependency>
-
Add a configuration file in
conf/alert/email/smtp.conf
; see below for an example configuration:# User to log into Appkit (service account) twigkit-user: admin twigkit-password: password # Email account to use to send alert emails from: foobar@twigkit.com password: foobar # SMTP details mail.smtp.host: smtp.gmail.com mail.smtp.port: 587 mail.smtp.auth: true mail.smtp.starttls.enable: true
-
Add another configuration file for the email template in
conf/alert/email/alerts/alerts.conf
; see below for an example configuration:email-template: http://localhost:8080/email/ subject-prefix: New report for saved query
-
Add the saved query alert scheduling form to the search header (header.tag):
<social:searchHeader query="${query}" action="${action}" logoImage="/assets/logo-google.png" logoHeight="42" logoImageAlt="Appkit for GSA"> <jsp:attribute name="searchFormBody"> <instant:result-list platformConf="platforms.gsa"> <instant:result> <a href="{{result.fields.url.val[0]}}"> <instant:field fieldName="title" /> </a> </instant:result> </instant:result-list> </jsp:attribute> <jsp:attribute name="searchControls"> <%-- Bookmarks --%> <widget:popover id="bookmark-list" title="Bookmarks" linkText="" align="right"> <social:bookmarkList emptyText="You do not currently have any bookmarks." user="${social:getCurrentUserProfile()}" date-format="dd MMM yyyy" /> </widget:popover> <%-- Saved Searches --%> <widget:popover id="saved-searches" title="Saved Searches" linkText="" align="right"> <alert:savedQueryAlertForm query="${query}" /> <alert:savedQueryAlertList user="${social:getCurrentUserProfile()}" action="${action}" date-format="dd MMM yyyy" emptyText="You do not currently have any saved searches." /> </widget:popover> </jsp:attribute> </social:searchHeader>
-
Create the email template JSP, in
src/main/webapp/WEB-INF/pages/email.jsp
. For example:<%@ page contentType="text/html" pageEncoding="UTF-8" %> <%@ include file="/WEB-INF/tags/client/taglibs.jspf" %> <search:twigkit> <search:platform var="delegatePlatform" conf="platforms.elasticsearch" /> <alert:platform delegatePlatform="${delegatePlatform}" /> <alert:query dateField="updated" /> <alert:response var="response" platform="${platform}" query="${query}"> </alert::response> </search:twigkit> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <h1>Automated alert for query ${query.value}</h1> <search:result-list response="response"> <search:result> <search:field name="title" /> <search:field name="summary" /> </search:result> </search:result-list> </html>
Note the following:
-
The 'alert seen' functionality is reliant on a field in the data specifying the date the document was last updated, in this case named
updated
-
The 'to address' of the email alert will either be chosen by the user via the form (default) or can be set by using the
toAddress
attribute on the saved query alert form tag. -
Appkit includes full user impersonation, so any security trimming is applied automatically.
Saved Query Alert Form tag attributes
query (twigkit.model.Query)
The Query object to be registered for alerting.
defaultTitle (java.lang.String)
Default title of a saved query (if no query supplied).
scheduleAlertText (java.lang.String)
Text to display above schedule component.
toAddress (java.lang.String)
The email address to which the alert should be sent. If not supplied (left empty), the user will be presented with a field to specify this (default behavior).
toAddressPlaceholderText (java.lang.String)
Placeholder text for 'to' email address field which is displayed if toAddress attribute is blank
toAddressLabelText (java.lang.String)
Label text for 'to' email address field which is displayed if toAddress attribute is blank
deliveryFrequencyLabelText (java.lang.String)
Text for label above scheduling component