Skip to main content

Inbox Gateway Automatch Portal

Join the conversation on the related Slate Community post

Are your users tired of matching messages in theย Inbox Gateway? "Hard linking" a message to a person record enables queries and reports that are otherwise too slow, but keeping up with a busy Inbox Gateway can be a daunting chore.

Try this portal that makes bulk-matching easy! This tool allows you to link messages with person records en masse when there's only one possible match. Messages with zero or multiple matches will be left in the Inbox Gateway for manual matching.

This tool is intended for Slate Captains or other power users who have access to Inbox Gateway. Scroll down to "How It Works" to learn about the inner workings of this portal.

Installing

Use this Suitcase code to install the portal: 9b1e5760-cbb1-4d1b-93ce-68505681bc47:rwf-test

We recommend trying this tool in your Test environment initially!

After loading the portal in your environment, you may wish to adjust the portal security. By default, it's limited to users with the Administrator role.

If your Test tag is named something other than 'test', adjust the tag name in the 'Get Confident Matches' and 'Get Batch' queries.

This portal has very little styling. If it does not work well with your branding, change the output of the 'Default' method to 'Framework + No Branding' to get rid of the branding entirely.

Usage

Start by clicking Generate Summary. A table of email-sending users and their unmatched messages will be generated along with a user filter list. Filtering by user can avoid timeouts if you have many unmatched messages.

Clicking Search for Matches is optional; it will tell you how many messages for the selected user (or all users) can be automatically matched.

Sample Batch will return messages for review. The message GUID, subject, and person GUID will be displayed. You can click the subject to display the message in a pop-up or the person GUID to open the person record. This step is designed to instill confidence that messages are being matched correctly.

Start Auto Match will begin matching messages for the selected user (or all users). The log at the bottom of the screen displays progress.

How Matches Are Selected

This tool mimics the standard Gateway Inbox's matching logic. Only messages sent to BCC gateway addresses are considered. Inbox Groups messages, outgoing messages, etc. are excluded.

"Confident" matches are selected by searching for Device values matching the message recipient with the following criteria:

  • Matched on Devices with type of 'email' or device_type category of 'email'.

  • Must match one and only one Person record.

  • Persons tagged with a tag named 'test' are excluded.

  • Device priority must not be Inactive.

How It Works

When the portal is first loaded, the Default method fires because it has a blank Action. The Default View contains the overall "shape" of the content with placeholders like

<div id="batch_sample"></div>

for content that will be lazy-loaded later. This view also contains a script comprising most of the guts of this portal.

Let's walk through each function defined in the JavaScript:

  • timestamp() returns a timestamp.

  • writeLog() takes a string, prefixes it with a timestamp, and writes it to the log. In this case, the log is one of those placeholder divs in the Default View.

  • getCmdWithUser() accepts a string, checks whether the "Filter by User" field has a user selected and, if so, appends &user_id=<user GUID> to the input string and returns it. Other functions pass method "action" strings to this function to optionally append the user filter parameter before calling a portal method.

  • getSummary() uses Slate's FW.Lazy.Fetch() function to call the portal method with action 'summary' and replace one of the placeholder div's with an HTML table. More on that later! It also write to the log via the writeLog() function, as do the rest of these functions.

  • getEasilyMatched() calls the 'automatch' method and replaces a chunk of content. Note how it uses getCmdWithUser() to optionally append the 'user_id' parameter.

  • sample() reads the value of the Sample Batch Size size field, fires the 'batch_sample' method, and replaces content.

  • automatch() is where the magic really happens. This function reads the Batch Size field and calls the 'batch_json' portal method, which returns JSON. Instead of using FW.Lazy.Fetch(), this function uses JQuery's ajax() function because we need more control over exactly how the results are processed. When the call finishes, ajax()'s built-in done() method checks whether the response was empty. If empty, it writes a message to the log. If not empty, it calls the processBatch() nested function.

  • processBatch() generates a random number and sets a counter, i, to zero. It inserts a new log entry into the page HTML, this time with our random number, batch_id, as the element id so we can find it again later. It then uses the forEach() method to loop through every message returned in the JSON response. It makes an ajax() POST call to /manage/inbox/gateway with a message GUID and the matching person GUID, exactly as if you clicked to manually save a match in the Inbox Gateway. For each POST that succeeds, the counter is incremented and the log entry is updated by the element id we stored earlier. jQuery AJAX calls are asynchronous by default, meaning the script hands each one off to the browser and moves on to the next action without waiting for a response from the server. When the server does respond, callbacks (like done()) handle the responses. Rather than trying to initiate 500 HTTP requests all at once, your browser queues them up in a semi-sane fashion, which you can see by pressing F12 and going to the Network tab. The asynchronous nature of these functions means you can start multiple batches at once and each 'batch' function scope will separately increment a counter. However, this doesn't gain any speed overall because you're still limited by your browser's HTTP queuing mechanisms.

Note that queuing up hundreds of HTTP requests at once is not a normal web development practice. Ideally, we'd update [message] at least a thousand rows at a time with an SQL UPDATE statement. Slate blocks direct updates to that table (for good reason), so RBAR is the only current option.

There are five methods in this portal and four views. Let's walk through what each method does:

  • Default displays the Default View with branding plus JavaScript libraries for jQuery and Framework (FW).

  • Get Summary Table runs the Get Summary query and returns the Summary Table view. The view contains an HTML table populated with query data via Liquid looping. This view also contains the Filter by User field. I put the field here because the Get Summary query decides what users to list in the drop-down; doing this during the initial portal load would make it sluggish. Note that this method uses the "AJAX Popup/No Branding" Output Type. Branding, jQuery, and FW should only be inserted into the page once; multiple times will cause JavaScript errors.

  • Get Confident Matches runs the Get Confident Matches query (with optional 'user_id' parameter) and returns the Confident Matches view containing a single line of HTML.

  • Get Sample Batch Table runs the Get Batch query with 'user_id' and 'top' (batch size) parameters. It then returns the Sample Batch Table view, which contains another HTML table. This table includes JavaScript links that can open pop-up modals.

  • Get Batch JSON also runs the Get Batch query but returns the response as JSON instead of HTML.

Notice that the Get Batch query is shared by two methods that return the data in different ways.

The queries in this portal are all custom SQL because each one uses one or more techniques not available in Configurable Joins. However, this portal is somewhat esoteric; most portals dealing with persons, applications, etc. will be able to use Configurable Joins.