Name

sn_oe_sfs.VACommonInputBuilder

Description

No description available

Script

var VACommonInputBuilder = Class.create();
VACommonInputBuilder.prototype = {
  initialize: function(inputs, channelLogger) {
      this.channelLogger = channelLogger;
      this.logger = new sn_oe_sfs.VACommonLogger(this.channelLogger, 'VACommonInputBuilder');
      this.logger.debug("VACommonInputBuilder channelLogger: " + JSON.stringify(this.channelLogger) + " \n inputs: " + JSON.stringify(inputs));
      this.requestContext = inputs.request_context ? inputs.request_context : {};
      this.richControl = inputs.rich_control;
      this.payload = inputs.payload;
      this.data = this.richControl.data && typeof this.richControl.data === 'string' ? JSON.parse(this.richControl.data) : this.richControl.data;
  },

  getRequestContext: function() {
      return this.requestContext;
  },

  getRichControl: function() {
      return this.richControl;
  },

  getPayload: function() {
      return this.payload;
  },

  getData: function() {
      return this.data;
  },

  // Request Context Inputs : for inbound transformers
  getInboundClickedValues: function() {
      return this.requestContext.clicked_values;
  },

  getInboundTypedValues: function() {
      return this.requestContext.typed_value;
  },

  getInboundAttachments: function() {
      return this.requestContext.attachments;
  },

  getInboundServiceURL: function() {
      return this.requestContext.serviceUrl;
  },

  getInboundTeamID: function() {
      return this.requestContext.team_id;
  },

  getTenantId: function() {
      return this.payload &&
          this.payload.requestData &&
          this.payload.requestData.channelData &&
          this.payload.requestData.channelData.tenant ? this.payload.requestData.channelData.tenant.id : null;
  },

  getInboundTenantID: function() {
      return this.requestContext.tenant_id;
  },

  getInboundProviderUserID: function() {
      return this.requestContext.provider_user_id;
  },

  // Rich Control Inputs
  getTemplate: function() {
      return this.richControl.templateName;
  },

  getTemplateFromContent: function() {
      return this.richControl.content.templateName;
  },

  getUIType: function() {
      return this.richControl.uiType;
  },

  getUITypeFromContent: function() {
      return this.richControl.content.uiType;
  },

  getItemType: function() {
      return this.richControl.itemType;
  },

  getMaskType: function() {
      return this.richControl.maskType;
  },

  getLabel: function() {
      return this.richControl.label;
  },

  getPromtMsg: function() {
      return this.richControl.promptMsg;
  },

  getScriptedData: function() {
      return this.richControl.scriptedData;
  },

  getCardData: function() {
      return this.getScriptedData() ? this.getScriptedData().cardData : null;
  },

  getCardName: function() {
      return this.richControl.scriptedData.cardName;
  },

  getCardTemplate: function() {
      return this.richControl.scriptedData.cardTemplate;
  },

  getHeader: function() {
      return this.richControl.header;
  },

  getHeaders: function() {
      return this.richControl.headers;
  },

  getValues: function() {
      return this.richControl.values;
  },

  getPaginationBreak: function() {
      return this.richControl.paginationBreak;
  },

  getTotalSearchResultsCount: function() {
      return this.richControl.totalSearchResultsCount;
  },

  getAgentInfo: function() {
      return this.richControl.agentInfo;
  },

  getContent: function() {
      return this.richControl.content;
  },

  getNavBtnLabel: function() {
      return this.richControl.navigationBtnLabel;
  },

  getImgURL: function() {
      return this.richControl.value;
  },

  getHTMLParams: function() {
      var richControl = this.richControl;
      return {
          "getImageURL": function() {
              return richControl.imageUrl;
          },
          "getImageHeight": function() {
              return richControl.imageHeight;
          },
          "getImageWidth": function() {
              return richControl.imageWidth;
          },
          "getLinks": function() {
              return richControl.links;
          }
      };
  },

  getActionType: function() {
      return this.richControl.type;
  },

  getMessage: function() {
      return this.richControl.message;
  },

  getSpinnerType: function() {
      return this.richControl.spinnerType;
  },

  getSpinnerWaitTime: function() {
      return this.richControl.spinnerWaitTime;
  },

  getDefaultOutputLink: function() {
      return this.richControl.value.action;
  },

  isControlRequired: function() {
      return this.richControl.required;
  },

  // Payload Inputs
  getActions: function() {
      return this.payload.actions;
  },

  getRequestData: function() {
      return this.payload.requestData;
  },

  getConversation: function() {
      return this.payload.requestData.conversation;
  },

  getPayloadMsg: function() {
      return this.payload.message;
  },

  //??
  getProviderUserID: function() {
      return this.payload.userId;
  },

  // Data inputs
  getId: function() {
      return this.data.id;
  },

  getTitle: function() {
      return this.data.title;
  },

  getLink: function() {
      return this.data.link;
  },

  getDescription: function() {
      return this.data.description;
  },

  // Processed Inputs
  getTemplateData: function(template, cardData, channel) { //value: teams|slack
      var templateName = template ? template : this.getTemplate();
      var data = cardData ? cardData : this.getData();
      var templateData = JSON.parse(sn_cs.VASystemObject.fillTemplateFromDataAndDeviceType(templateName, JSON.stringify(data), channel, true));
      return templateData ? templateData : data;
  },

  getBotId: function() {
      var recepientId = this.payload.requestData.recipient.id;
      return recepientId.substring(recepientId.indexOf(':') + 1);
  },

  getOptions: function() {
      return this.richControl.options;
  },

  getOptionsSorted: function() {
      var options = this.getOptions();
      if (options && options.length > 0) {
          //sort options label alphabetically
          //DEF0282888: Added && condition to avoid sorting for carousel
          if (this.getUIType() != "Boolean" && !(options[0].attachment)) {
              options.sort(function(firstLabel, secondLabel) {
                  if (firstLabel.label && secondLabel.label) {
                      var labelOne = firstLabel.label.toLowerCase(),
                          labelTwo = secondLabel.label.toLowerCase();
                      if (labelOne < labelTwo)
                          return -1;
                      if (labelOne > labelTwo)
                          return 1;
                      return 0;
                  }
              });
          }
      }
      return options;
  },

  getChannelLogger: function() {
      return this.channelLogger;
  },

  getSmartLinksMetadata: function() {
      return this.richControl.smartLinksMetadata;
  },

  getSmartLinkId: function(card) {
      return card ? card.dataNowSmartLink : (this.richControl.value ? this.richControl.value.dataNowSmartLink : null);
  },

  getSmartLinkTarget: function(card) {
  	if (card) {
  		return card.target || card.type || '_blank';
  	} else if (this.richControl.value) {
  		return this.richControl.value.target || '_blank'; 
  	}
  	return '_blank';
  },

  getSmartLinkData: function(card) {
  	if (card && card.source) {
  		return card;
  	} else if (this.getSmartLinksMetadata() && this.getSmartLinkId(card)) {
  		return this.getSmartLinksMetadata()[this.getSmartLinkId(card)];
  	}
  	return null;
  },

  type: 'VACommonInputBuilder'
};

Sys ID

e52f66d77303011065afe3d29f148bc3

Offical Documentation

Official Docs: