Gmail Contextual Gadget (Part 1)

So last time I posted I said that I wanted to develop a widget of sorts that gave the user the ability to save message threads from Gmail into a CRM application. From what I researched there was two possible solutions to the problem that I was facing one was to use an application called Rapportive and the other was to use Google’s new Gmail Gadgets API.

Though I said that Rapportive gave a nice interface and had potential, I found out that it could fail if Google ever decides to change its email interface. This actually came true recently with something called Google People which adds a bar with contact information on the right side of your email. Though with this recent change it didn’t affect my idea of creating a button to do the features that I wanted.

To get more info on building the gadget you can follow this guide.

There are two parts to building a gadget and that’s to have the gadget itself and a manifest that reads where the gadget is hosted whenever you load your gmail.

In the application manifest what you need a couple of things. One of those things is what google calls extractors, which are used to search certain sections of your email for whatever regular expression you want to look for. These extractors can be used to trigger your application to run whenever the desired regular expression appears. In the following example for all my extractors I wanted to display the gadget I created for all possible strings inside my Message ID, Recipient Email, Sender Email, and Subject line.

 

<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<!-- EXTRACTOR -->

<Extension id="MessageIDExtractor" type="contextExtractor">
	<Name>Message ID Extractor</Name>
	<Url>google.com:MessageIDExtractor</Url>
	<Param name="message_id" value=".*"/>
	<Triggers ref="showButton"/>
	<Scope ref="emailMessage_ID"/>
	<Container name="mail"/>
</Extension>

<Extension id="RecipientEmailExtractor" type="contextExtractor">
  <Name>Recipient email extractor</Name>
  <Url>google.com:RecipientEmailExtractor</Url>
  <Param name="recipient_email" value=".*"/>
  <Triggers ref="showButton"/>
  <Scope ref="emailtoAddress"/>
  <Scope ref="emailCC"/>
  <Container name="mail"/>
</Extension>

<Extension id="SenderEmailExtractor" type="contextExtractor">
	<Name>Sender Email Extractor</Name>
	<Url>google.com:SenderEmailExtractor</Url>
	<Param name="sender_email" value=".*"/>
	<Triggers ref="showButton" />
	<Scope ref="emailSender"/>
	<Container name="mail"/>
</Extension>

<Extension id="RawSubjectExtractor" type="contextExtractor">
	<Name>Raw Subject Extractor</Name>
	<Url>google.com:RawSubjectExtractor</Url>
	<Param name="subject" value=".*"/>
	<Triggers ref="showButton" />
	<Scope ref="rawemailSubject"/>
	<Container name="mail"/>
</Extension>

The next part you need in your application manifest is the location of where you hosted your gadget as shown below.

<Extension id="showButton" type="gadget">
  Send To Quickbase Gadget
  <Url>http://test.com/gadgets/STQBGadget.xml</Url>
  <Container name="mail"/>
</Extension>

The last part you need for the manifest to work is the scope, which tells the extractors what parts to read

<!-- SCOPE -->
<Scope id="emailMessage_ID">
   tag:google.com,2010:auth/contextual/extractor/MESSAGE_ID
   <Reason>This application searches for the Message ID field of an email.</Reason>
</Scope>
<Scope id="emailtoAddress">
  tag:google.com,2010:auth/contextual/extractor/TO_ADDRESS
  <Reason>This application searches for the To field of an email</Reason>
</Scope>
<Scope id="emailCC">
  tag:google.com,2010:auth/contextual/extractor/CC_EMAIL
  <Reason>This application searches for the CC field of an email</Reason>
</Scope>
<Scope id="emailSender">
   tag:google.com,2010:auth/contextual/extractor/FROM_ADDRESS
   <Reason>This application searches for the From field of an email.</Reason>
</Scope>
<Scope id="rawemailSubject">
   tag:google.com,2010:auth/contextual/extractor/RAW_SUBJECT
   <Reason>This application searches for the Subject field of an email.</Reason>
</Scope>
</ApplicationManifest>

On my next post I will discuss how I coded the gadget spec which sends data to Quickbase on what I extracted from the email.

Leave a comment

Your email address will not be published. Required fields are marked *