Search code examples
xmlwebviewoutlookadd-inoutlook-web-addins

I'm having issues getting the webview working for a contextual add-in I'm building for Outlook


The add-in should detect and highlight a specific URL using regex match (and it does this part) and when a user clicks on the detected area a webview should pop-up and display the webpage from the link. But it's not doing that.It's always saying that Something went wrong and we couldn't start this add-in.

Here's my code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp">
  <Id>02d1356d-95ba-466a-9eb8-91e37dac827e</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Outlook add-In"/>
  <Description DefaultValue="A Outlook add-in."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-128.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://www.contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Mailbox"/>
  </Hosts>
  
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.1"/>
    </Sets>
  </Requirements>
  <FormSettings>
    <Form xsi:type="ItemRead">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://localhost:3000/src/taskpane/index.html"/>
        <RequestedHeight>250</RequestedHeight>
      </DesktopSettings>
    </Form>
  </FormSettings>
  <Permissions>ReadWriteItem</Permissions>

  <Rule xsi:type="RuleCollection" Mode="And">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL" RegExValue="https://google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
                
    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL2" 
  RegExValue="google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
  </Rule>
  <DisableEntityHighlighting>false</DisableEntityHighlighting>
  
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <!-- VersionOverrides for the v1.1 schema -->
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <Requirements>
        <bt:Sets DefaultMinVersion="1.5">
          <bt:Set Name="Mailbox" />
        </bt:Sets>
      </Requirements>
      <Hosts>
        <Host xsi:type="MailHost">

          <DesktopFormFactor>
            <!-- DetectedEntity -->
            <ExtensionPoint xsi:type="DetectedEntity">
              <Label resid="contextLabel" />
              <SourceLocation resid="detectedEntityURL" />
              <Rule xsi:type="RuleCollection" Mode="And">                                            
                <Rule xsi:type="ItemIs" ItemType="Message"/>
                  <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL" RegExValue="https://google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
                
    <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL2" 
  RegExValue="google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
<!--I have to use 2 Rules using AND because contextual add-ins do not directly work with urls -->
            </Rule>
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>

      <Resources>
      
        <bt:Images>
          <bt:Image id="icon16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
          <bt:Image id="icon32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
          <bt:Image id="icon80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
        </bt:Images>
    
        <bt:Urls>
          <bt:Url id="detectedEntityURL" DefaultValue="https://localhost:3000/src/taskpane/index.html"/>
        </bt:Urls>
        <bt:ShortStrings>
          <bt:String id="contextLabel" DefaultValue="my outlook add-in "/>
        </bt:ShortStrings>
      </Resources>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>


Solution

  • I have noticed the following rules chained with AND operator:

    <Rule xsi:type="RuleCollection" Mode="And">                                            
        <Rule xsi:type="ItemIs" ItemType="Message"/>
        <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL" RegExValue="https://google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
                  
        <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="UURL2" 
      RegExValue="google\.com/[a-zA-Z0-9_]+" PropertyName="BodyAsPlaintext"/>
    <!--I have to use 2 Rules using AND because contextual add-ins do not directly work with urls -->
    </Rule>
    

    So, I'd suggest playing with a single regex condition. If it doesn't work correctly either, you may try filing an issue on the officejs repo at github. Or just try using the sample add-in at https://github.com/OfficeDev/Outlook-Add-In-Contextual-Regex/blob/master/contoso-order-number-manifest.xml .

    Also you need to make sure the detectedEntityURL file is available online.