Class: MediaUpgradeOffer

Property Summary

(Array<string>) medias

An array of medias the Operator offered to upgrade to. The possible values are: 'audio', 'phone', 'video'.

(string) media Deprecated

The media that the Operator offered to upgrade to. The media is one of: 'audio', 'video'.

Deprecated. Use medias instead.

Instance Method Summary

Instance Method Details

# (Promise) select(media, options)

Calling this function will upgrade both Operator and Visitor to the offered media.

Examples:

Accepting media upgrade offer with media offered by the Operator

function chooseMedia(requestedMedias) {
  return Promise.resolve(requestedMedias[0]);
}

function askVisitorsPhoneNumber() {
  return Promise.resolve('+12058675309');
}

function getUpgradeOptions(requestedMedias) {
  chooseMedia(requestedMedias).then(function(media) {
    if (media === 'phone') {
      return askVisitorsPhoneNumber().then(function(phoneNumber) {
        return {
          media: 'phone',
          options: {phoneNumber: phoneNumber}
        };
      });
    } else {
      return Promise.resolve({media: media});
    }
  });
}

var engagementRequest = salemove.requestEngagement('text');

engagementRequest.engagementPromise.then(function(engagement) {
  var handleMediaUpgradeOffer = function(mediaUpgradeOffer) {
    getUpgradeOptions(mediaUpgradeOffer.medias).then(function(args) {
      return mediaUpgradeOffer.select(args.media, args.options);
    }).catch(function(error) {
      // Handle error
    });
  };

  engagement.addEventListener(
    engagement.EVENTS.MEDIA_UPGRADE_OFFER,
    handleMediaUpgradeOffer
  );
});

Parameters:

  • media ( string ) The media type that Visitor wants to upgrade to. Must be one of the media types the Operator offered.
  • options ( Object )

Options Hash: (options):

  • phone_number ( ?string ) The Visitor's phone number to use when media that Visitor wants to upgrade to is 'phone'.

Returns:

  • ( Promise ) — Fulfilled with an empty object or rejected with an Error if the input is invalid. The Error may have one of the following causes: INVALID_INPUT, INTERNAL_ERROR.

# (Promise) decline()

Calling this function will decline the media upgrade offer.

Examples:

Declining media upgrade offer

var engagementRequest = salemove.requestEngagement('text');

engagementRequest.engagementPromise.then(function(engagement) {
  var handleMediaUpgradeOffer = function(mediaUpgradeOffer) {
    mediaUpgradeOffer.decline().then(function() {
      // Handle successfully declined
    }).catch(function(error) {
      // Handle error
    });
  };

  engagement.addEventListener(
    engagement.EVENTS.MEDIA_UPGRADE_OFFER,
    handleMediaUpgradeOffer
  );
});

Returns:

  • ( Promise ) — Fulfilled with an empty object or rejected with an Error. The Error may have one of the following causes: INTERNAL_ERROR.

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: