Skip to content

Instantly share code, notes, and snippets.

@markdon
Created January 27, 2022 04:00
Show Gist options
  • Save markdon/48adb17ce836db062657f2b7136caa2f to your computer and use it in GitHub Desktop.
Save markdon/48adb17ce836db062657f2b7136caa2f to your computer and use it in GitHub Desktop.
Outlook add-in get SkypeTeamsMeetingUrl from EWS
export default async function getSkypeTeamsMeetingUrl(
itemId: string
): Promise<string | undefined> {
console.log("getSkypeTeamsMeetingUrl itemId", itemId);
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP1"/>
</soap:Header>
<soap:Body>
<GetItem xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:AdditionalProperties>
<t:ExtendedFieldURI PropertyType="String" PropertyName="SkypeTeamsMeetingUrl" PropertySetId="00020329-0000-0000-c000-000000000046"/>
</t:AdditionalProperties>
</ItemShape>
<ItemIds>
<t:ItemId Id="${itemId}"/>
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>`;
return await new Promise<string | undefined>((resolve, reject) => {
Office.context.mailbox.makeEwsRequestAsync(
xml,
(asyncResult: Office.AsyncResult<string>) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.error(asyncResult.error);
} else {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(asyncResult.value, "text/xml");
const value = xmlDoc.querySelector(
"ExtendedFieldURI + Value"
)?.textContent;
console.log("getSkypeTeamsMeetingUrl value", value);
resolve(value || undefined);
}
}
);
});
}
export function saveItem(): Promise<string> {
console.log("saveItem");
return new Promise<string>((resolve, reject) => {
Office.context.mailbox.item.saveAsync({}, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.error(asyncResult.error);
reject(asyncResult.error);
} else {
console.log(
"Office.context.mailbox.item.saveAsync ~ asyncResult.value",
asyncResult.value
);
resolve(asyncResult.value);
}
});
});
}
saveItem().then(getSkypeTeamsMeetingUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment