1.2.0 • Published 3 years ago

@cordova-plugin-agconnect/appmessaging v1.2.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
3 years ago

Cordova Plugin AGC App Messaging

Contents


1. Introduction

This plugin enables communication between Huawei App Messaging SDK and Cordova platform. It exposes all functionality provided by Huawei App Messaging SDK.


2. Installation Guide

Before you get started, you must register as a HUAWEI Developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

2.1. Creating a Project in AppGallery Connect

Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:

  1. Sign in to AppGallery Connect and select My projects.
  2. Select your project from the project list or create a new one by clicking the Add Project button.
  3. Go to Project settings > General information, and click Add App. If an app exists in the project, and you need to add a new one, expand the app selection area on the top of the page and click Add App.
  4. On the Add App page, enter the app information, and click OK.

2.2. Obtaining agconnect-services.json and agconnect-services.plist

  1. Sign in to AppGallery Connect and select your project from My Projects. Then go to Project settings > General information. In the App information field,

    • If platform is Android, click agconnect-services.json button to download the configuration file.
    • If platform is iOS, click agconnect-services.plist button to download the configuration file.

2.3. Cordova

  1. Install Cordova CLI.

    npm install -g cordova
  2. Create a new Cordova project or use existing Cordova project.

    • To create new Cordova project, you can use cordova create path [id [name [config]]] [options] command. For more details please follow CLI Reference - Apache Cordova.
  3. Update the widget id property which is specified in the config.xml file. It must be same with client > package_name value of the agconnect-services.json and agconnect-services.plist files.

  4. Add the Android or iOS platform to the project if haven't done before.

    cordova platform add android
    cordova platform add ios
  5. Install AGC App Messaging Cordova Plugin to the project.

  • Run the following command in the root directory of your project to install it through npm.

    cordova plugin add @cordova-plugin-agconnect/appmessaging

2.3.1. iOS App Development

  1. Add agconnect-services.plist file to the app's root directory of your Xcode project.

  2. Check Signing & Capabilities tab page of your Xcode project.

  3. Run the application.

    cordova run ios --device

2.3.2. Android App Development

  1. Copy agconnect-services.json file to <project_root>/platforms/android/app directory your Android project.

  2. Run the application.

    cordova run android --device

2.4. Ionic

  1. Install Ionic CLI.

    npm install -g @ionic/cli
  2. Create a new Ionic project or use existing Ionic project.

  3. Enable the Cordova integration if haven't done before.

    ionic integrations enable cordova
  4. Update the widget id property which is specified in the config.xml file. It must be same with client > package_name value of the agconnect-services.json and agconnect-services.plist files.

  5. Set preference in your Ionic project config.xml.

    <!--platform iOS-->
     <preference name="deployment-target" value="11.0" />
     <preference name="SwiftVersion" value="5" />
  6. Add the Android or iOS platform to the project if haven't done before.

    ionic cordova platform add android
    ionic cordova platform add ios
  7. Install AGC App Messaging Cordova Plugin to the project.

    a. Run the following command in the root directory of your project to install it through npm.

    ionic cordova plugin add @cordova-plugin-agconnect/appmessaging
  8. Copy agc-appmessaging folder from node_modules/@cordova-plugin-agconnect/appmessaging/ionic/dist directory to node_modules/@ionic-native directory.

2.4.1 iOS App Development
  1. Add agconnect-services.plist file to the app's root directory of your Xcode project.

  2. Check Signing & Capabilities tab page of your Xcode project.

  3. Run the application.

    ionic cordova run ios --device
2.4.2. Android App Development
  1. Copy agconnect-services.json file to <project_root>/platforms/android/app directory your Android project.

  2. Run the application.

    ionic cordova run android --device

NOTICE:

App Messaging Cordova Plugin currently doesn't support changing orientation. Only a single landscape or portrait layout can be used.


3. API Reference

3.1. AGCAppMessaging

Represents the message processing class.

Public Method Summary

MethodReturn TypeDescription
setFetchMessageEnable(enabled:boolean)Promise<void>Sets whether to allow the App Messaging SDK to synchronize in-app message data from the AppGallery Connect server.
setDisplayEnable(enabled:boolean)Promise<void>Sets whether to allow the App Messaging SDK to display in-app messages.
isDisplayEnable()Promise<boolean>Checks whether the App Messaging SDK is allowed to display in-app messages.
isFetchMessageEnable()Promise<boolean>Checks whether the App Messaging SDK is allowed to synchronize in-app message data from the AppGallery Connect server.
addListener(event: Events, callback: (appMessage: CardMessage or PictureMessage or BannerMessage, dismissType?: DismissType) => void)Promise<void>Adds a listener for given event value.
setForceFetch()Promise<string>Sets the forcible in-app message data obtaining flag. When the flag is enabled, you can obtain latest in-app message data from the AppGallery Connect server in real time. This method is only to support on Android Platform.
setDisplayLocation(location:Location)Promise<void>Sets the display position of a pop-up or image message.
trigger(eventId:string)Promise<void>Triggers a custom event.

Public Methods

setFetchMessageEnable(enabled:boolean)

Sets whether to allow the App Messaging SDK to synchronize in-app message data from the AppGallery Connect Server.

Parameters
NameTypeDescription
enabledbooleanIndicates whether to allow the App Messaging SDK to synchronize in-app message data from the AppGallery Connect server. The options are as follows:true: yesfalse: no.The default value is true.
Return Type
TypeDescription
Promise<void>Empty Promise.
Call Example
async function setFetchMessageEnable() {
  const enabled: boolean = true;
  await AGCAppMessaging.setFetchMessageEnable(enabled);
}
setDisplayEnable(enabled:boolean)

Sets whether to allow the App Messaging SDK to display in-app messages.

Parameters
NameTypeDescription
enabledbooleanIndicates whether to allow the App Messaging SDK to display in-app messages.The options are as follows:true: yesfalse: noThe default value is true.
Return Type
TypeDescription
Promise<void>Empty Promise.
Call Example
async function setDisplayEnable() {
  const enabled: boolean = true;
  await AGCAppMessaging.setDisplayEnable(enabled);
}
isDisplayEnable()

Checks whether to allow the App Messaging SDK to display in-app messages.

Return Type
TypeDescription
Promise<boolean>Indicates whether to allow the App Messaging SDK to display in-app messages. The options are as follows:true: yesfalse: no
Call Example
async function isDisplayEnable() {
  await AGCAppMessaging.isDisplayEnable();
}
isFetchMessageEnable()

Checks whether to allow the App Messaging SDK to synchronize in-app message data from the AppGallery Connect Server.

Return Type
TypeDescription
Promise<boolean>Indicates whether to allow the App Messaging SDK to synchronize in-app message data from the AppGallery Connect server. The options are as follows:true: yesfalse: no
Call Example
async function isFetchMessageEnable() {
  await AGCAppMessaging.isFetchMessageEnable();
}
addListener(event: Events, callback: (appMessage: CardMessage | PictureMessage | BannerMessage, dismissType?: DismissType) => void)

Adds a listener for given event value.

Parameters
NameTypeDescription
eventEventsIndicated which event listener will be added for.
callbackfunctionCallback function called when the given event is triggered.
Return Type
TypeDescription
Promise<void>Empty Promise.
Call Example
async function addListener() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const id: string = appMessage.getId();
    }
  );
}
setForceFetch()

Sets the flag for whether to obtain in-app message data from the AppGallery Connect Server in real time by force.

After this method is called, the App Messaging SDK does not immediately request data from the AppGallery Connect Server. When the next trigger event takes place, the App Messaging SDK forcibly obtains in-app message data from the AppGallery Connect Server. For iOS platform: Enable the debugging mode for your app. Add the '-AGConnectDeveloperMode' launch parameter to the app scheme. Start your app in Xcode debug-mode. Notice:

  • The setForceFetch API can be used only for message testing.
  • The forcible data obtaining flag is bound to the AAID of the test device. After you uninstall and reinstall the app or clear app data on the device, the flag will be reset.
Return Type
TypeDescription
Promise<string>Returns string 'Enabled' if operation is successful.
Call Example
async function setForceFetch() {
    const result: string = await AGCAppMessaging.setForceFetch();
    console.log(result);
}
setDisplayLocation(location:Location)

Sets the display position of a pop-up or image message.

Parameters
NameTypeDescription
locationLocationLocation instance.
Return Type
TypeDescription
Promise<void>Empty Promise.
Call Example
async function setDisplayLocation() {
  const location: Location = Location.BOTTOM;
  await AGCAppMessaging.setDisplayLocation(location);
}
trigger(eventId:string)

Triggers a custom event.

Parameters
NameTypeDescription
eventIdstringID of a custom event.
Return Type
TypeDescription
Promise<void>Empty Promise.
Call Example
async function trigger() {
  const eventId = "OnAppForeGround";
  await AGCAppMessaging.trigger(eventId);
}

3.2. BannerMessage

Represents the banner message object class.

Public Method Summary

MethodReturn TypeDescription
getId()stringObtains the ID of an in-app message.
getMessageType()MessageTypeObtains the message type.
getStartTime()numberObtains the start timestamp of a message.
getEndTime()numberObtains the end timestamp of a message.
getFrequencyType()numberObtains the display frequency type of a message.
getFrequencyValue()numberObtains the display frequency of a message.
getTestFlag()TestFlagChecks whether an in-app message is a test message.
getTriggerEvents()string[]Obtain the ID of a trigger event.
getBanner()BannerObtains the banner information of a message.

Public Methods

getId()

Obtains the ID of an in-app message.

Return Type
TypeDescription
stringMessage ID.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const id: string = appMessage.getId();
      console.log(id);
    }
  );
}
getMessageType()

Obtains the message type.

Return Type
TypeDescription
MessageTypeMessage type. The banner message type is MessageType.BANNER.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const messageType: MessageType = appMessage.getMessageType();
      console.log(messageType);
    }
  );
}
getStartTime()

Obtains the start timestamp of a message.

Return Type
TypeDescription
numberStart timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const startTime: number = appMessage.getStartTime();
      console.log(startTime);
    }
  );
}
getEndTime()

Obtains the end timestamp of a message.

Return Type
TypeDescription
numberEnd timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const endTime: number = appMessage.getEndTime();
      console.log(endTime);
    }
  );
}
getFrequencyType()

Obtains the display frequency of a message.

Return Type
TypeDescription
numberDisplay frequency type of a message. The options are as follows: 1: only once.2: once every X days. The value of X is the return value of getFrequencyValue.3: X days per day The value of X is the return value of getFrequencyValue.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyType: number = appMessage.getFrequencyType();
      console.log(frequencyType);
    }
  );
}
getFrequencyValue()

Obtains the display frequency limit of an in-app message.

Return Type
TypeDescription
numberDisplay frequency limit of an in-app message. This parameter is valid only when getFrequencyType is set to 2 or 3.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyValue: number = appMessage.getFrequencyValue();
      console.log(frequencyValue);
    }
  );
}
getTestFlag()

Checks whether an in-app message is a test message.

Return Type
TypeDescription
TestFlagChecks whether an in-app message is a test message. The options are as follows:1: test message0: non-test message
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const testFlag: TestFlag = appMessage.getTestFlag();
      console.log(testFlag);
    }
  );
}
getTriggerEvents()

A collection of in-app message trigger event types, which are selected by you in AppGallery Connect.

Return Type
TypeDescription
string[]A collection of in-app message trigger event types.The App Messaging SDK matches an event ID with the trigger event types of an in-app message. If the ID is in TriggerEvent, the message will be displayed.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const triggerEvents: string[] = appMessage.getTriggerEvents();
      console.log(triggerEvents);
    }
  );
}
getBanner()

Obtains the banner information of a message.

Return Type
TypeDescription
BannerBanner information of a message.
Call Example
async function example() {
  const banner: Banner = appMessage.getBanner();
  console.log(JSON.stringify(banner));
}

3.3. Banner

Represents a banner message.

Public Method Summary

MethodReturn TypeDescription
getTitle()stringObtains the title of a banner message.
getTitleColor()stringObtains the title color of a banner message.
getTitleColorOpenness()numberObtains the title color transparency of a banner message.
getBody()stringObtains the body of a banner message.
getBodyColor()stringObtains the body color of a banner message.
getBodyColorOpenness()numberObtains the body color transparency of a banner message.
getBackgroundColor()stringObtains the background color of a banner message.
getBackgroundColorOpenness()numberObtains the background color transparency of a banner message.
getPictureUrl()stringObtains the image URL of a banner message.
getActionUrl()stringObtains the redirection URL in a banner message.

Public Methods

getTitle()

Obtains the title of a banner message.

Return Type
TypeDescription
stringTitle of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const title: string = banner.getTitle();
      console.log(title);
    }
  );
}
getTitleColor()

Obtains the title color of a banner message.

Return Type
TypeDescription
stringTitle color of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const titleColor: string = banner.getTitleColor();
      console.log(titleColor);
    }
  );
}
getTitleColorOpenness()

Obtains the title color transparency of a banner message.

Return Type
TypeDescription
numberTitle color transparency of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const titleColorOpenness: number = banner.getTitleColorOpenness();
      console.log(titleColorOpenness);
    }
  );
}
getBody()

Obtains the body of a banner message.

Return Type
TypeDescription
stringBody of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const body: string = banner.getBody();
      console.log(body);
    }
  );
}
getBodyColor()

Obtains the body color of a banner message.

Return Type
TypeDescription
stringBody color of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const bodyColor: string = banner.getBodyColor();
      console.log(bodyColor);
    }
  );
}
getBodyColorOpenness()

Obtains the body color transparency of a banner message.

Return Type
TypeDescription
numberBody color transparency of a banner message. The value ranges from 0 to 100.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const bodyColorOpenness: number = banner.getBodyColorOpenness();
      console.log(bodyColorOpenness);
    }
  );
}
getBackgroundColor()

Obtains the background color of a banner message.

Return Type
TypeDescription
stringBackground color of a banner message, which is an RGB value.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const backgroundColor: string = banner.getBackgroundColor();
      console.log(backgroundColor);
    }
  );
}
getBackgroundColorOpenness()

Obtains the background color transparency of a banner message.

Return Type
TypeDescription
numberBackground color transparency of a banner message. The value ranges from 0 to 100.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const backgroundColorOpenness: string = banner.getBackgroundColorOpenness();
      console.log(backgroundColorOpenness);
    }
  );
}
getPictureUrl()

Obtains the image URL of a banner message.

Return Type
TypeDescription
stringImage URL of a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const pictureUrl: string = banner.getPictureUrl();
      console.log(pictureUrl);
    }
  );
}
getActionUrl()

Obtains the redirection URL in a banner message.

Return Type
TypeDescription
stringRedirection URL in a banner message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const banner: Banner = appMessage.getBanner();
      const actionUrl: string = banner.getActionUrl();
      console.log(actionUrl);
    }
  );
}

3.4. CardMessage

Represents a pop-up message.

Public Method Summary

MethodReturn TypeDescription
getId()stringObtains the ID of an in-app message.
getMessageType()MessageTypeObtains the message type.
getStartTime()numberObtains the start timestamp of a message.
getEndTime()numberObtains the end timestamp of a message.
getFrequencyType()numberObtains the display frequency type of a message.
getFrequencyValue()numberObtains the display frequency of a message.
getTestFlag()TestFlagChecks whether an in-app message is a test message.
getTriggerEvents()string[]Obtain the ID of a trigger event.
getCard()CardObtains the card information of a pop-up message.

Public Methods

getId()

Obtains the ID of an in-app message.

Return Type
TypeDescription
stringMessage ID.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const id: string = appMessage.getId();
      console.log(id);
    }
  );
}
getMessageType()

Obtains the message type.

Return Type
TypeDescription
MessageTypeMessage type. The banner message type is MessageType.CARD.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const messageType: MessageType = appMessage.getMessageType();
      console.log(messageType);
    }
  );
}
getStartTime()

Obtains the start timestamp of a message.

Return Type
TypeDescription
numberStart timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const startTime: number = appMessage.getStartTime();
      console.log(startTime);
    }
  );
}
getEndTime()

Obtains the end timestamp of a message.

Return Type
TypeDescription
numberEnd timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const endTime: number = appMessage.getEndTime();
      console.log(endTime);
    }
  );
}
getFrequencyType()

Obtains the display frequency of a message.

Return Type
TypeDescription
numberDisplay frequency type of a message. The options are as follows: 1: only once.2: once every X days. The value of X is the return value of getFrequencyValue.3: X days per day The value of X is the return value of getFrequencyValue.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyType: number = appMessage.getFrequencyType();
      console.log(frequencyType);
    }
  );
}
getFrequencyValue()

Obtains the display frequency limit of an in-app message.

Return Type
TypeDescription
numberDisplay frequency limit of an in-app message. This parameter is valid only when getFrequencyType is set to 2 or 3.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyValue: number = appMessage.getFrequencyValue();
      console.log(frequencyValue);
    }
  );
}
getTestFlag()

Checks whether an in-app message is a test message.

Return Type
TypeDescription
TestFlagChecks whether an in-app message is a test message. The options are as follows:1: test message0: non-test message
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const testFlag: TestFlag = appMessage.getTestFlag();
      console.log(testFlag);
    }
  );
}
getTriggerEvents()

A collection of in-app message trigger event types, which are selected by you in AppGallery Connect.

Return Type
TypeDescription
string[]A collection of in-app message trigger event types.The App Messaging SDK matches an event ID with the trigger event types of an in-app message. If the ID is in TriggerEvent, the message will be displayed.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const triggerEvents: string[] = appMessage.getTriggerEvents();
      console.log(triggerEvents);
    }
  );
}
getCard()

Obtains the card information of a pop-up message.

Return Type
TypeDescription
CardObtains the card information of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      console.log(JSON.stringify(card));
    }
  );
}

3.5. Card

Represents the card class in a pop-up message.

Public Method Summary

MethodReturn TypeDescription
getTitle()stringObtains the title of a pop-up message.
getTitleColor()stringObtains the title color of a pop-up message.
getTitleColorOpenness()numberObtains the title color transparency of a pop-up message.
getBody()stringObtains the body of a pop-up message.
getBodyColor()stringObtains the body color of a pop-up message.
getBodyColorOpenness()numberObtains the body color transparency of a pop-up message.
getBackgroundColor()stringObtains the background color of a pop-up message.
getBackgroundColorOpenness()numberObtains the background color transparency of a pop-up message.
getPortraitPictureUrl()stringObtains the URL of the portrait image for a pop-up message.
getLandscapePictureUrl()stringObtains the URL of the landscape image for a pop-up message.
getMajorButton()ButtonObtains the primary button of a pop-up message.
getMinorButton()ButtonObtains the secondary button of a pop-up message.

Public Methods

getTitle()

Obtains the title of a pop-up message.

Return Type
TypeDescription
stringTitle of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const title: string = card.getTitle();
      console.log(title);
    }
  );
}
getTitleColor()

Obtains the title color of a pop-up message.

Return Type
TypeDescription
stringTitle color of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const titleColor: string = card.getTitleColor();
      console.log(titleColor);
    }
  );
}
getTitleColorOpenness()

Obtains the title color transparency of a pop-up message.

Return Type
TypeDescription
numberTitle color transparency of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const titleColorOpenness: number = card.getTitleColorOpenness();
      console.log(titleColorOpenness);
    }
  );
}
getBody()

Obtains the body of a pop-up message.

Return Type
TypeDescription
stringBody of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const body: string = card.getBody();
      console.log(body);
    }
  );
}
getBodyColor()

Obtains the body color of a pop-up message.

Return Type
TypeDescription
stringBody color of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const bodyColor: string = card.getBodyColor();
      console.log(bodyColor);
    }
  );
}
getBodyColorOpenness()

Obtains the body color transparency of a pop-up message.

Return Type
TypeDescription
numberBody color transparency of a pop-up message. The value ranges from 0 to 100.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const bodyColorOpenness: number = card.getBodyColorOpenness();
      console.log(bodyColorOpenness);
    }
  );
}
getBackgroundColor()

Obtains the background color of a pop-up message.

Return Type
TypeDescription
stringBackground color of a pop-up message, which is an RGB value.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const backgroundColor: string = card.getBackgroundColor();
      console.log(backgroundColor);
    }
  );
}
getBackgroundColorOpenness()

Obtains the background color transparency of a pop-up message.

Return Type
TypeDescription
numberBackground color transparency of a pop-up message. The value ranges from 0 to 100.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const backgroundColorOpenness: string = card.getBackgroundColorOpenness();
      console.log(backgroundColorOpenness);
    }
  );
}
getPortraitPictureUrl()

Obtains the URL of the portrait image for a pop-up message.

Return Type
TypeDescription
stringURL of the portrait image for a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const portraitPictureUrl: string = card.getPortraitPictureUrl();
      console.log(portraitPictureUrl);
    }
  );
}
getLandscapePictureUrl()

Obtains the URL of the landscape image for a pop-up message.

Return Type
TypeDescription
stringURL of the landscape image for a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const landscapePictureUrl: string = card.getLandscapePictureUrl();
      console.log(landscapePictureUrl);
    }
  );
}
getMajorButton()

Obtains the primary button of a pop-up message.

Return Type
TypeDescription
ButtonPrimary button of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const majorButton: Button = card.getMajorButton();
      console.log(JSON.stringify(majorButton));
    }
  );
}
getMinorButton()

Obtains the secondary button of a pop-up message.

Return Type
TypeDescription
ButtonSecondary button of a pop-up message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const minorButton: Button = card.getMinorButton();
      console.log(JSON.stringify(minorButton));
    }
  );
}

3.6. Button

Represents a pop-up message button.

Public Method Summary

MethodReturn TypeDescription
getText()stringObtains the button name.
getTextColor()stringObtains the button name text color.
getTextColorOpenness()numberObtains the transparency of the button name text color.
getActionUrl()stringObtains the redirection URL of the button.

Public Methods

getText()

Obtains the button name.

Return Type
TypeDescription
stringButton name.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const minorButton: Button = card.getMinorButton();
      const text: string = minorButton.getText();
      console.log(text);
    }
  );
}
getTextColor()

Obtains the button name text color.

Return Type
TypeDescription
stringButton name text color.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const minorButton: Button = card.getMinorButton();
      const textColor: string = minorButton.getTextColor();
      console.log(textColor);
    }
  );
}
getTextColorOpenness()

Obtains the transparency of the button name text color.

Return Type
TypeDescription
numberTransparency of the button name text color.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const minorButton: Button = card.getMinorButton();
      const textColorOpenness: string = minorButton.getTextColorOpenness();
      console.log(textColorOpenness);
    }
  );
}
getActionUrl()

Obtains the redirection URL of the button.

Return Type
TypeDescription
stringRedirection URL of the button.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const card: Card = appMessage.getCard();
      const minorButton: Button = card.getMinorButton();
      const actionUrl: string = minorButton.getActionUrl();
      console.log(actionUrl);
    }
  );
}

3.7. PictureMessage

Represents an image message.

Public Method Summary

MethodReturn TypeDescription
getId()stringObtains the ID of an in-app message.
getMessageType()MessageTypeObtains the message type.
getStartTime()numberObtains the start timestamp of a message.
getEndTime()numberObtains the end timestamp of a message.
getFrequencyType()numberObtains the display frequency type of a message.
getFrequencyValue()numberObtains the display frequency of a message.
getTestFlag()TestFlagChecks whether an in-app message is a test message.
getTriggerEvents()string[]Obtain the ID of a trigger event.
getPicture()PictureObtains the information of an image message.

Public Methods

getId()

Obtains the ID of an in-app message.

Return Type
TypeDescription
stringMessage ID.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const id: string = appMessage.getId();
      console.log(id);
    }
  );
}
getMessageType()

Obtains the message type.

Return Type
TypeDescription
MessageTypeMessage type. The banner message type is MessageType.PICTURE.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const messageType: MessageType = appMessage.getMessageType();
      console.log(messageType);
    }
  );
}
getStartTime()

Obtains the start timestamp of a message.

Return Type
TypeDescription
numberStart timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const startTime: number = appMessage.getStartTime();
      console.log(startTime);
    }
  );
}
getEndTime()

Obtains the end timestamp of a message.

Return Type
TypeDescription
numberEnd timestamp of a message, accurate to milliseconds.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const endTime: number = appMessage.getEndTime();
      console.log(endTime);
    }
  );
}
getFrequencyType()

Obtains the display frequency of a message.

Return Type
TypeDescription
numberDisplay frequency type of a message. The options are as follows: 1: only once.2: once every X days. The value of X is the return value of getFrequencyValue.3: X days per day The value of X is the return value of getFrequencyValue.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyType: number = appMessage.getFrequencyType();
      console.log(frequencyType);
    }
  );
}
getFrequencyValue()

Obtains the display frequency limit of an in-app message.

Return Type
TypeDescription
numberDisplay frequency limit of an in-app message. This parameter is valid only when getFrequencyType is set to 2 or 3.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const frequencyValue: number = appMessage.getFrequencyValue();
      console.log(frequencyValue);
    }
  );
}
getTestFlag()

Checks whether an in-app message is a test message.

Return Type
TypeDescription
TestFlagChecks whether an in-app message is a test message. The options are as follows:1: test message0: non-test message
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const testFlag: TestFlag = appMessage.getTestFlag();
      console.log(testFlag);
    }
  );
}
getTriggerEvents()

A collection of in-app message trigger event types, which are selected by you in AppGallery Connect.

Return Type
TypeDescription
string[]A collection of in-app message trigger event types.The App Messaging SDK matches an event ID with the trigger event types of an in-app message. If the ID is in TriggerEvent, the message will be displayed.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const triggerEvents: string[] = appMessage.getTriggerEvents();
      console.log(triggerEvents);
    }
  );
}
getPicture()

Obtains the information of an image message.

Return Type
TypeDescription
PictureInformation of an image message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const picture: Picture = appMessage.getPicture();
      console.log(JSON.stringify(picture));
    }
  );
}

3.8. Picture

Represents the information of an image message.

Public Method Summary

MethodReturn TypeDescription
getPictureUrl()stringImage URL of an image message.
getActionUrl()stringObtains the redirection URL of an image message.

Public Methods

getPictureUrl()

Image URL of an image message.

Return Type
TypeDescription
stringImage URL of an image message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const picture: Picture = appMessage.getPicture();
      const pictureUrl: string = picture.getPictureUrl();
      console.log(pictureUrl);
    }
  );
}
getActionUrl()

Obtains the redirection URL of an image message.

Return Type
TypeDescription
stringRedirection URL of an image message.
Call Example
async function example() {
  await AGCAppMessaging.addListener(
    Events.ON_MESSAGE_DISPLAY_LISTENER,
    (appMessage) => {
      const picture: Picture = appMessage.getPicture();
      const actionUrl: string = picture.getActionUrl();
      console.log(actionUrl);
    }
  );
}

3.9. Constants

Enum MessageType

Obtains the message type.

FieldValueDescription
UN_SUPPORT0Undefined type.
CARD1Pop-up message.
PICTURE2Image message.
BANNER3Banner message.

Enum Location

Display position of a pop-up or image message.

FieldValueDescription
BOTTOM0Bottom.
CENTER1Center.

Enum TestFlag

TestFlag constants.

FieldValueDescription
NON_TEST_MESSAGE0Non-test message.
TEST_MESSAGE1Test message.

Enum DismissType

Message closing constants.

FieldValueDescription
UNKNOWN_DISMISS_TYPE0Undefined type.
CLICK1Close button or redirection link tapping.
CLICK_OUTSIDE2Tapping outside the message borders.
BACK_BUTTON3Back button tapping.
AUTO4Auto.
SWIPE5SWIPE.

Enum Events

Events constants for event callbacks.

FieldValueDescription
ON_MESSAGE_CLICK_LISTENERonMessageClickListens on message tap events.
ON_MESSAGE_DISPLAY_LISTENERonMessageDisplayListens on message display events.
ON_MESSAGE_DISMISS_LISTENERonMessageDismissListens on message closing events.
ON_MESSAGE_ERROR_LISTENERonMessageErrorListens on message error events.

3.10. Data Types

BaseProperties

Represents common base properties among all message type.

FieldTypeDescription
idnumberID of an in-app message.
startTimenumberStart timestamp of a message.
endTimenumberEnd timestamp of a message.
frequencyTypenumberDisplay frequency type of a message.
frequencyValuenumberDisplay frequency of a message.
testFlagnumberIn-app message is a test message or not.
triggerEventsstring[]IDs of a trigger events.

BannerMessageProps

Represents the banner message object.

FieldTypeDescription
baseBasePropertiesBase properties object.
bannerBannerPropsBanner object.

BannerProps

Represents the information of a banner.

FieldTypeDescription
baseProbsMessage detail.
pictureURLstringImag