Skip to content

Parse push notification messages #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
e10jon opened this issue Jan 31, 2022 · 2 comments
Closed

Parse push notification messages #395

e10jon opened this issue Jan 31, 2022 · 2 comments

Comments

@e10jon
Copy link

e10jon commented Jan 31, 2022

I am able to subscribe to push notifications and receive events via a callback url. The problem is, when those XML events come in, how do I parse them into library objects?

Example XML is below. I would like to be able to do something like const message = new EWS.Message(rawXml) but I can't figure it out.

<?xml version="1.0" encoding="UTF-8"?>
<soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
  <soap11:Header>
    <t:RequestServerVersion xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2013_SP1" />
  </soap11:Header>
  <soap11:Body>
    <m:SendNotification xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:SendNotificationResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Notification>
            <t:SubscriptionId>EgBoaXRleDIuZmxob3VzZS5pbnQQAAAAp6l9rcjsFU6mlII+hEsD+vKtJTm15NkIEAAAALo1KNrW4vpPpUP1v28hRgY=</t:SubscriptionId>
            <t:PreviousWatermark>AQAAAAvWxetbiOtLqiriWXdIMNJZ02MNAAAAAAE=</t:PreviousWatermark>
            <t:MoreEvents>false</t:MoreEvents>
            <t:ModifiedEvent>
              <t:Watermark>AQAAAAvWxetbiOtLqiriWXdIMNJo02MNAAAAAAE=</t:Watermark>
              <t:TimeStamp>2022-01-31T12:29:40Z</t:TimeStamp>
              <t:ItemId Id="AAMkAGRhMjgzNWJhLWUyZDYtNGZmYS1hNTQzLWY1YmY2ZjIxNDYwNgBGAAAAAAB8Z3FUo3PGR7xle04joYd/BwB/Y9hyJKYbSZfW+0lCePJHAAAAAAENAAB/Y9hyJKYbSZfW+0lCePJHAABBO0ssAAA=" ChangeKey="DwAAAA==" />
              <t:ParentFolderId Id="AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBDQAAAA==" ChangeKey="AQAAAA==" />
            </t:ModifiedEvent>
            <t:ModifiedEvent>
              <t:Watermark>AQAAAAvWxetbiOtLqiriWXdIMNJr02MNAAAAAAE=</t:Watermark>
              <t:TimeStamp>2022-01-31T12:29:40Z</t:TimeStamp>
              <t:FolderId Id="AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBDQAAAA==" ChangeKey="AgAAAA==" />
              <t:ParentFolderId Id="AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBCAAAAA==" ChangeKey="AQAAAA==" />
            </t:ModifiedEvent>
          </m:Notification>
        </m:SendNotificationResponseMessage>
      </m:ResponseMessages>
    </m:SendNotification>
  </soap11:Body>
</soap11:Envelope>

Separately, I had to hard-code the following XML string response to send to EWS such that the push subscription would remain open. Is there a way to do this via the library?

<?xml version="1.0"?>
<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <SubscriptionStatus>OK</SubscriptionStatus>
    </SendNotificationResult>
  </s:Body>
</s:Envelope>
@e10jon
Copy link
Author

e10jon commented Feb 5, 2022

I was able to figure out the parsing like this:

const domParser = new EWS.DOMParser()
const xmlDoc = domParser.parseFromString(xmlString)
const xml2Js = new EWS.xml2JsObject()
const jsObj = xml2Js.parseXMLNode(xmlDoc.documentElement, true)

console.log(jsObj)

{
  __prefix: 'soap11',
  __xmlns: {
    soap11: 'http://schemas.xmlsoap.org/soap/envelope/',
    m: 'http://schemas.microsoft.com/exchange/services/2006/messages',
    t: 'http://schemas.microsoft.com/exchange/services/2006/types'
  },
  Header: {
    __prefix: 'soap11',
    RequestServerVersion: {
      __prefix: 't',
      __type: 'RequestServerVersion',
      Version: 'Exchange2013_SP1'
    }
  },
  Body: {
    __prefix: 'soap11',
    SendNotification: {
      __prefix: 'm',
      __type: 'SendNotification',
      ResponseMessages: {
        __prefix: 'm',
        __type: 'ResponseMessages',
        SendNotificationResponseMessage: {
          __prefix: 'm',
          __type: 'SendNotificationResponseMessage',
          ResponseClass: 'Success',
          ResponseCode: 'NoError',
          Notification: {
            __prefix: 'm',
            __type: 'Notification',
            SubscriptionId: 'EgBoaXRleDIuZmxob3VzZS5pbnQQAAAAp6l9rcjsFU6mlII+hEsD+vKtJTm15NkIEAAAALo1KNrW4vpPpUP1v28hRgY=',
            PreviousWatermark: 'AQAAAAvWxetbiOtLqiriWXdIMNJZ02MNAAAAAAE=',
            MoreEvents: 'false',
            ModifiedEvent: [
              {
                __prefix: 't',
                __type: 'ModifiedEvent',
                Watermark: 'AQAAAAvWxetbiOtLqiriWXdIMNJo02MNAAAAAAE=',
                TimeStamp: '2022-01-31T12:29:40Z',
                ItemId: {
                  __prefix: 't',
                  __type: 'ItemId',
                  Id: 'AAMkAGRhMjgzNWJhLWUyZDYtNGZmYS1hNTQzLWY1YmY2ZjIxNDYwNgBGAAAAAAB8Z3FUo3PGR7xle04joYd/BwB/Y9hyJKYbSZfW+0lCePJHAAAAAAENAAB/Y9hyJKYbSZfW+0lCePJHAABBO0ssAAA=',
                  ChangeKey: 'DwAAAA=='
                },
                ParentFolderId: {
                  __prefix: 't',
                  __type: 'ParentFolderId',
                  Id: 'AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBDQAAAA==',
                  ChangeKey: 'AQAAAA=='
                }
              },
              {
                __prefix: 't',
                __type: 'ModifiedEvent',
                Watermark: 'AQAAAAvWxetbiOtLqiriWXdIMNJr02MNAAAAAAE=',
                TimeStamp: '2022-01-31T12:29:40Z',
                FolderId: {
                  __prefix: 't',
                  __type: 'FolderId',
                  Id: 'AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBDQAAAA==',
                  ChangeKey: 'AgAAAA=='
                },
                ParentFolderId: {
                  __prefix: 't',
                  __type: 'ParentFolderId',
                  Id: 'AQMkAGRhMjgzNWJhLWUyZDYtNGZmAGEtYTU0My1mNWJmNmYyMTQ2MDYALgAAA3xncVSjc8ZHvGV7TiOhh38BAH9j2HIkphtJl9b7SUJ48kcAAAIBCAAAAA==',
                  ChangeKey: 'AQAAAA=='
                }
              }
            ]
          }
        }
      }
    }
  }
}

@gautamsi
Copy link
Owner

gautamsi commented Feb 7, 2022

there is no built in method to parse this. you are on right track here

@gautamsi gautamsi closed this as completed Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants