Class

WidgetMediaUpgradeRequest

WidgetMediaUpgradeRequest

Example

Allowing both 'phone' and 'audio' upgrades on 'audio' request.

  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 handleWidgetMediaUpgradeRequests = function(request) {
      getUpgradeOptions(request.medias).then(function(args) {
        return engagement.upgrade(args.media, args.options);
      }).catch(function(error) {
        // Handle error
      });
    };

    engagement.addEventListener(
      engagement.EVENTS.WIDGET_MEDIA_UPGRADE_REQUEST,
      handleWidgetMediaUpgradeRequests
    );
  });

Members

string

# media

The media requested by the visitor from the visitor's media widget. Is one of: 'audio', 'video'.
Deprecated:
Array

# medias

An array of medias requested by the visitor from the visitor's media widget. The possible values are: 'audio', 'phone', 'video'.