Class

MediaUpgradeOffer

MediaUpgradeOffer

Members

string

# media

The media that the operator offered to upgrade to. The media is one of: 'audio', 'video'.
Deprecated:
Array.<string>

# medias

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

Methods

# decline() → {Promise}

Declines the media upgrade offer.
Fulfilled with an empty object or rejected with an Error. The Error may have one of the following:
  • INVALID_INPUT: When input is invalid.
  • CONFLICT: When engagement has ended or upgrade request has already been accepted/canceled.
  • NETWORK_TIMEOUT
  • INTERNAL_ERROR
Promise
Example

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
    );
  });

# select(media, options) → {Promise}

Upgrades both the operator and the visitor to the offered media.
Parameters:
Name Type Attributes Description
media string The media type that visitor wants to upgrade to. Must be one of the media types the operator offered.
options Object Media upgrade options.
phone_number string <nullable>
The visitor's phone number to use when media that visitor wants to upgrade to is 'phone'.
phoneExtension string <nullable>
The visitor's phone number extension, which can contain commas and up to 7 digits. The commas represent a two second wait between digits. This will be used when media that visitor wants to upgrade to is 'phone'.
Fulfilled with an empty object or rejected with an Error. The Error may have one of the following:
  • INVALID_INPUT: When input is invalid.
  • CONFLICT: When engagement has ended or upgrade request has already been declined/canceled.
  • NETWORK_TIMEOUT
  • INTERNAL_ERROR
Promise
Example

Accepting media upgrade offer with media offered by the operator

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

  function askVisitorsPhoneNumber() {
    return Promise.resolve({phoneNumber: '+12058675309', phoneExtension: '1,23'});
  }

  function getUpgradeOptions(requestedMedias) {
    return chooseMedia(requestedMedias).then(function(media) {
      if (media === 'phone') {
        return askVisitorsPhoneNumber().then(function({phoneNumber, phoneExtension}) {
          return {
            media: 'phone',
            options: {
              phoneNumber: phoneNumber,
              phoneExtension: phoneExtension
            }
          };
        });
      } 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
    );
  });