The Natural Language MailBot

Announcing the LUIS MailBot NLP skill

Reilly Sweetland
MailBots
5 min readMar 6, 2019

--

Does a bot have to pretend like it’s human to justify the title of “bot”? We at MailBots think the answer is no, but the real answer is probably a bit more nuanced.

A piece of technology can take on a spectrum of “human likeness”.

A little human likeness is good. Perfect human likeness is awesome. But somewhere in between is a bit...odd.

Uncanny androids are creepy. Uncanny bots, on the other hand, can leave us with feelings of frustration, betrayal and embarrassment — for example, when you realize a bot deliberately tricked you into thinking it was human.

So, the uncanny valley (☝️) is a challenge we decided to forego, at least for now.

MailBots have UI elements that do not try to hide their good-natured robot character. They accepts commands (email commands) and provide buttons, as any well-intentioned robot should.

A MailBot with buttons

A MailBot that only works with commands, buttons and HTML, however, is not living up to its full potential. A NLP-capable MailBot could do way more. For example:

  • Automatically filter incoming emails
  • Provide suggested responses to support inquiries
  • Perform research on entities (names, locations and companies) mentioned in emails.
  • Determine and log email sentiment

Introducing the LUIS MailBots Skill

Yesterday we published our LUIS MailBot skill. It is simple to use, thanks to the MailBots platform and some heavy lifting by the folks at Microsoft.

Aside: What’s a skill? A MailBot skill is a collection of functions or behaviors that can be installed and shared between multiple MailBots.

Our new LUIS skill provides several handy language parsing functions, as well as middleware that can decipher every MailBot request.

Example Application
To demonstrate this new skill, we created a working Amazon shopping assistant MailBot example. It can recognize two LUIS intents: Shopping.BuyItem and Shopping.FindItem — two of several dozen pre-built LUIS knowledge domains.

Example MailBot demo using the Sandbox email emulator

The complete source of this example can be found here.

Setting up the LUIS MailBot Skill

Adding natural language parsing to your MailBot takes only a minute. It is really only two steps: Training your natural language model on luis.ai, then connecting your MailBot to LUIS using this new MailBot skill.

Here are the specific steps for our Amazon shopping assistant example.

LUIS Setup

  1. Go to Luis.ai and create an account.
  2. Under Build > Intents > Add prebuilt domain intent add the Shopping.FindItem and Shopping.BuyItem intents.
  3. Under Build > Entities > Add prebuilt entity add the keyPhase entity
  4. Click “Train”, then “Publish” in the top right (you must do this with each change)
  5. Under Manage > Application Settings > Keys and Endpoints. Copy your Endpoint. It should look something like: https://<id>.api.cognitive.microsoft.com/luis/v2.0/apps/?subscription-key=&q=

Note: With a few modifications you can extract places, dates, times and locations and more, but we’ll keep things simple for now.

Install and configure the LUIS MailBot skill
To connect your MailBot with LUIS, install the @mailbots/luis-ai module.

npm install @mailbots/luis-ai

Then require it at the top of app.js.

const mbLuis = require(“@mailbots/luis-ai”);

Next, let’s tell it where to access our LUIS resource.

const mbLuis.configure({endpoint:  'endpoint_from_above'})

Understand Natural Language 👩‍💻→🤖
Now that LUIS is set up we can make use of several functions to extract meaning from natural language. For example, here we are finding most likely intent when someone emails shop@your-bot.eml.bot

mailbot.onCommand('shop', async bot => {
const topIntent = await mbLuis.getTopIntent(bot);
bot.webhook.respond();
});

Key Phrases
LUIS can also extracts key phrases — people, places, company names, times and more. In our case, it’s what the person is looking to buy.

const keyPhrases = await getKeyPhrases(bot);

Using Our NLP Data
If the user’s intent is to search for a product, our simple shopping assistant sends them a link to an appropriate Amazon search results page. If the user’s intent is to buy a product, our assistant sends them to the same page with slightly different wording.

let searchUrl =“https://www.amazon.com/s/?field-keywords=" + encodeURIComponent(searchPhrases[0]);

Alternative: NLP Middleware
Instead of explicitly calling the NLP functions as shown above, we could have used the provided middleware. This invokes LUIS on every request.

mailbot.app.use(mbLuis.luisMiddleware({endpoint: '[your endpoint]'}// Every handler is now LUIS enabled
mailbot.onCommand('shop', bot => {
console.log(bot.skills.luis) // <-- NLP data available here
});
mailbot.onCommand('help', bot => {
console.log(bot.skills.luis) // <-- NLP data available here, too!
});

Extra: Developer Settings Page
Just for demonstration (and to ease the LUIS setup process) we exposed a developer settings page with instructions for configuring Luis.ai. This can be enabled by adding this line to app.js:

mailbot.onSettingsViewed(mbLuis.createLuisAiSettingsPage);

If you are sharing your MailBot with others you would not keep this setting page. You could, however, make your own settings page that asks for shopping preferences, price ranges and more.

Add More LUIS Intents
Now that your MailBot and LUIS are connected, you can enable additional pre-trained knowledge domains within LUIS, tell it to extract additional key phrases (people, locations, etc) or train LUIS on your own data set.

LUIS has many prebuilt knowledge domains

Where to go from here?
Why not use the Amazon API to insert search results directly into the email response? Or allow the user to search different e-commerce sites depending on their preferences? You could also use MailBots’ time-handling features to check a product’s price every day and send an email if it reaches a low-price threshold. The MailBots LUIS natural language processing skill take care of the plumbing so you can impart human-like powers to your shopping assistant..but not too human-like, remember? 😬🤖

View the complete source code here and sign up for a LUIS account here. Fork it, clone it and create a MailBot for free.

Request an Invitation
We are still limiting the number of developers on the platform. If you do not yet have an invitation, feel free to fill out our developer survey. We’re looking forward to hearing your feedback!

--

--

Reilly Sweetland
MailBots

Founder of Gopher (YC S17), FollowUpThen, Internet Simplicity (acq 2016), TypeRoom. Productivity enthusiast, autodidact, hacker, nutritionist, husband, dad.