Search code examples
google-apps-marketplacegoogle-gadgetgmail-contextual-gadgetsgoogle-apps-for-education

Cannot make Gmail contextual gadget work - 2015 API version


I am currently working on a Gmail Contextual Gadget for a non-profit organization. We followed the official Google tutorials on https://developers.google.com/gmail/contextual_gadgets with the goal of building a Hello World app.

We did the following:

  1. Create an app on https://console.developers.google.com/
  2. Activate Google Marketplace SDK
  3. Activate GMail contextual gadget with appropriate Extractor and Gadget URLs.
  4. Deploy the app for the Non-Profit organization users.
  5. Send us emails containing "Hello World".

However, we are not able to make it work (it should print Hello World below the emails). We checked our servers hosting the XMs, and Google definitely hits our gadget_helloworld.xml file.

Hereby are the files content. Could someone please give a hand on this subject?

It is hard to find up to date documentation on this topic, as a lot of things changed with the Google API. I think it would be helpful for the community to give an open source working sample of code updated on last-2015.

Best,

Content of the Extractor - manifest_helloworld.xml

<?xml version="1.0" encoding="UTF-8"?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
    <script id="tinyhippos-injected" />
    <Extension id="HelloWorldExtractor" type="contextExtractor">
        <Name>Hello World Extractor</Name>
        <Url>google.com:HelloWorld</Url>
        <Triggers ref="HelloWorld" />
        <Scope ref="emailBody" />
        <Scope ref="emailSubject" />
        <Container name="mail" />
    </Extension>
    <Extension id="HelloWorld" type="gadget">
        <Name>HelloWorld Gadget</Name>
        <Url>XXXX_MY_DOMAIN/gadget_files/gadget_helloworld.xml</Url>
        <Container name="mail" />
        <!--  Uncomment this to enable Caja.  -->
        <!--  Param name="caja" value="enabled"/>  -->
    </Extension>
    <Scope id="emailBody">
        <Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
        <Reason>Necessary for reason 1</Reason>
    </Scope>
    <Scope id="emailSubject">
        <Url>tag:google.com,2010:auth/contextual/extractor/SUBJECT</Url>
        <Reason>Necessary for reason 2</Reason>
    </Scope>
</ApplicationManifest>

Content of the Gadget - gadget_helloworld.xml

<?xml version="1.0" encoding="UTF-8"?>
<Module>
    <script id="tinyhippos-injected" />
    <ModulePrefs title="Hello World" description="Matches and echoes 'Hello World' string in emails" height="20" author="ACME" author_email="[email protected]" author_location="Bermuda">
        <!--  Declare feature dependencies.  -->
        <!--
 This one is not specific to Gmail contextual gadgets. 
-->
        <Require feature="dynamic-height" />
        <!--
 The next feature, Caja, is optional, and is supported for
     use only within test domains. Uncomment the tag only for
     non-production gadgets. 
-->
        <!--  <Require feature="caja"/>  -->
        <!--
 The next feature, google.contentmatch, is required for all
     Gmail contextual gadgets.
     <Param> - specify one or more comma-separated extractor IDs in
     a param named "extractors". This line is overridden by the extractor ID
     in the manifest, but is still expected to be present. 
-->
        <Require feature="google.contentmatch">
            <Param name="extractors">google.com:HelloWorld</Param>
        </Require>
    </ModulePrefs>
    <!--
 Define the content type and display location. The settings
   "html" and "card" are required for all Gmail contextual gadgets. 
-->
    <Content type="html" view="card"><![CDATA[<p>Hello World</p>
 <script type="text/javascript">
 <!-- Fetch the array of content matches. -->
 matches = google.contentmatch.getContentMatches();
 var matchList = document.createElement('UL');
 var listItem;
 var extractedText;

 <!-- Iterate through the array and display output for each match. -->
 for (var match in matches) {
 for (var key in matches[match]) {
 listItem = document.createElement('LI');
 extractedText = document.createTextNode(key + ": " + matches[match][key]);
 listItem.appendChild(extractedText);
 matchList.appendChild(listItem);
 }
 }
 document.body.appendChild(matchList);
 gadgets.window.adjustHeight(100);
 </script>]]></Content>
</Module>

Solution

  • I had a similar issue of it not activating and the solution for me was to make the "Extractor param name" set to "hello" and and the "Extractor param value" set to ".*" -- According to the docs the important part is the value field:

    If you really do want your gadget to be triggered by all possible values in the extractor's default output, explicitly set the regular expression as value=".*". This makes it clear that you have cast a wide net by design.