Office.NotificationMessages interface

NotificationMessages 对象作为项目的 notificationMessages 属性返回。

方法

addAsync(key, JSONmessage, options, callback)

向项目添加通知。

addAsync(key, JSONmessage, callback)

向项目添加通知。

getAllAsync(options, callback)

返回某个项目的所有项和邮件。

getAllAsync(callback)

返回某个项目的所有项和邮件。

removeAsync(key, options, callback)

删除某个项目的通知邮件。

removeAsync(key, callback)

删除某个项目的通知邮件。

replaceAsync(key, JSONmessage, options, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key, JSONmessage, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

方法详细信息

addAsync(key, JSONmessage, options, callback)

向项目添加通知。

addAsync(key: string, JSONmessage: NotificationMessageDetails, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

用于引用此通知邮件的开发人员指定的项。 开发人员可以在以后用它来修改此邮件。 其长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要添加到项目的通知邮件的 JSON 对象。 它包含一个 NotificationMessageDetails 对象。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要说明

  • 在 Outlook 网页版、Windows (新版和经典版) 以及 Mac 上,每条消息最多可以设置五个通知。 设置更多将返回 NumberOfNotificationMessagesExceeded 错误。 在 Android 和 iOS 上的 Outlook 中,每封邮件只能设置一个通知。 设置附加通知将替换上一个通知。

  • 每个加载项只允许一个 InsightMessage 类型的通知。 尝试添加更多将引发错误。

  • 在新式 Outlook 网页版和新版 Outlook on Windows 中,只能在 Compose 模式下添加InsightMessage通知。

  • 在 Android 和 iOS 上的 Outlook 中,仅ProgressIndicator支持 、 和InformationalMessageErrorMessage通知类型。

  • 在撰写模式下,虽然每种通知类型的样式在其他 Outlook 客户端上有所不同,但 Android 版和 iOS 版 Outlook 中的通知都使用相同的样式。 通知消息始终以信息图标为前缀。

  • 当前使用该loadItemByIdAsync方法加载的消息不支持此addAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Adds a progress indicator to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.ProgressIndicator,
    message: "Progress indicator with id = " + id
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add progress notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added progress notification with id = ${id}.`);
});

...

// Adds an informational notification to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Non-persistent informational notification message with id = " + id,
    icon: "PG.Icon.16",
    persistent: false
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add informational notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added informational notification with id = ${id}.`);
});

...

// Adds a persistent information notification to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Persistent informational notification message with id = " + id,
    icon: "PG.Icon.16",
    persistent: true
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add persistent informational notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added persistent informational notification with id = ${id}.`);
});

...

// Adds an error notification to the mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
const details =
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.ErrorMessage,
    message: "Error notification message with id = " + id
  };
Office.context.mailbox.item.notificationMessages.addAsync(id, details, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to add error notification with id = ${id}. Try using a different ID.`);
    return;
  }
  console.log(`Added error notification with id = ${id}.`);
});

addAsync(key, JSONmessage, callback)

向项目添加通知。

addAsync(key: string, JSONmessage: NotificationMessageDetails, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

用于引用此通知邮件的开发人员指定的项。 开发人员可以在以后用它来修改此邮件。 其长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要添加到项目的通知邮件的 JSON 对象。 它包含一个 NotificationMessageDetails 对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要说明

  • 在 Outlook 网页版、Windows (新版和经典版) 以及 Mac 上,每条消息最多可以设置五个通知。 设置更多将返回 NumberOfNotificationMessagesExceeded 错误。 在 Android 和 iOS 上的 Outlook 中,每封邮件只能设置一个通知。 设置附加通知将替换上一个通知。

  • 每个加载项只允许一个 InsightMessage 类型的通知。 尝试添加更多将引发错误。

  • 在新式 Outlook 网页版和新版 Outlook on Windows 中,只能在 Compose 模式下添加InsightMessage通知。

  • 在 Android 和 iOS 上的 Outlook 中,仅ProgressIndicator支持 、 和InformationalMessageErrorMessage通知类型。

  • 在撰写模式下,虽然每种通知类型的样式在其他 Outlook 客户端上有所不同,但 Android 版和 iOS 版 Outlook 中的通知都使用相同的样式。 通知消息始终以信息图标为前缀。

  • 当前使用该loadItemByIdAsync方法加载的消息不支持此addAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

getAllAsync(options, callback)

返回某个项目的所有项和邮件。

getAllAsync(options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<NotificationMessageDetails[]>) => void): void;

参数

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<Office.NotificationMessageDetails[]>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . value结果的属性是一个对象数NotificationMessageDetails组。

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Gets all the notification messages and their keys for the current mail item.
Office.context.mailbox.item.notificationMessages.getAllAsync((asyncResult) => {
  if (asyncResult.status === Office.AsyncResultStatus.Failed) {
    console.log(asyncResult.error.message);
    return;
  }
  console.log(JSON.stringify(asyncResult.value));
});

getAllAsync(callback)

返回某个项目的所有项和邮件。

getAllAsync(callback?: (asyncResult: Office.AsyncResult<NotificationMessageDetails[]>) => void): void;

参数

callback

(asyncResult: Office.AsyncResult<Office.NotificationMessageDetails[]>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 . value结果的属性是一个对象数NotificationMessageDetails组。

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

removeAsync(key, options, callback)

删除某个项目的通知邮件。

removeAsync(key: string, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要删除的通知邮件的项。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要提示: 当前使用该loadItemByIdAsync方法加载的消息不支持此removeAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Removes a notification message from the current mail item.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
Office.context.mailbox.item.notificationMessages.removeAsync(id, (result) => {
  if (result.status === Office.AsyncResultStatus.Failed) {
    console.log(`Failed to remove notification with id = ${id}. ${result.error.message}.`);
    return;
  }
  console.log(`Removed notification with id = ${id}.`);
});

removeAsync(key, callback)

删除某个项目的通知邮件。

removeAsync(key: string, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要删除的通知邮件的项。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要提示: 当前使用该loadItemByIdAsync方法加载的消息不支持此removeAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

replaceAsync(key, JSONmessage, options, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key: string, JSONmessage: NotificationMessageDetails, options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要替换的通知邮件的项。 长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要替换现有邮件的新通知邮件的 JSON 对象。 它包含一个 NotificationMessageDetails 对象。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们希望访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要提示: 当前使用该loadItemByIdAsync方法加载的消息不支持此replaceAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/35-notifications/add-getall-remove.yaml

// Replaces a notification message of a given key with another message.
const id = (document.getElementById("notificationId") as HTMLInputElement).value;
Office.context.mailbox.item.notificationMessages.replaceAsync(
  id,
  {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Notification message with id = " + id + " has been replaced with an informational message.",
    icon: "icon2",
    persistent: false
  },
  (result) => {
    if (result.status === Office.AsyncResultStatus.Failed) {
      console.log(`Failed to replace notification with id = ${id}. ${result.error.message}.`);
      return;
    }
    console.log(`Replaced notification with id = ${id}.`);
  });

replaceAsync(key, JSONmessage, callback)

将带有给定项的通知邮件替换为另一封邮件。

如果带有指定项的通知邮件不存在,replaceAsync 将添加通知。

replaceAsync(key: string, JSONmessage: NotificationMessageDetails, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

key

string

要替换的通知邮件的项。 长度不能超过 32 个字符。

JSONmessage
Office.NotificationMessageDetails

一个包含要替换现有邮件的新通知邮件的 JSON 对象。 它包含一个 NotificationMessageDetails 对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 当该方法完成时, callback 将使用类型 Office.AsyncResult为 .

返回

void

注解

API 集:邮箱 1.3

最低权限级别读取项目

适用的 Outlook 模式:Compose 或 Read

重要提示: 当前使用该loadItemByIdAsync方法加载的消息不支持此replaceAsync方法。 有关详细信息,请参阅 在多封邮件上激活 Outlook 加载项。