Skip to main content

Definir Contato (name, gender, email, etc...) quando Logado


Gostaria de confirmar se a implementação abaixo é válida, pois ao fazer alguns testes não

No caso, se o usuário estiver logado
if (browsingContext.Common.Shopper.IsAuthenticated)
deve ser indicado os dados de contato

Envia os dados de contato ao entrar no chat

/*jshint esversion: 6 */
(function () {
    window.onload = function () {

        var blipClient = new BlipChat()
            .withAppKey('KEY')
            .withButton({ "color": "#3a183d" })
            .withoutHistory()

            .withEventHandler(BlipChat.ENTER_EVENT, function () {

                console.log('BlipChat log event - enter');

                if (browsingContext.Common.Shopper.IsAuthenticated) {
                    blipClient
                    .withAccount({
                        name: browsingContext.Common.Shopper.Name,
                        fullName: browsingContext.Common.Shopper.Name + ' ' + browsingContext.Common.Shopper.SurName,
                        gender: browsingContext.Common.Customer.Gender,
                        email: browsingContext.Common.Shopper.Email,
                        phoneNumber: browsingContext.Common.Customer.ExtendedProperties.Phone.Value,
                        extras: {
                            CustomerID: browsingContext.Common.Customer.CustomerID
                        }
                    })
                    .build();
                }
            })
            ;
        blipClient.build();
    };
})();

Referência:

Resources - LIME Protocol - Account

Bruno
  • Specialist
  • 4 de fevereiro de 2020

@AndyDaSilva52

Você já conseguiu resolver?


Deixei a implementação no site:

<script src="https://unpkg.com/blip-chat-widget" type="text/javascript"></script>
<script type="text/javascript">
  /*jshint esversion: 6 */
(function () {
        //window.onload = function () {
      		
      		var blipClient = new BlipChat()
            .withAppKey('KEY')
            .withButton({"color":"#3a183d"})
            //.withoutHistory()
            
            .withEventHandler(BlipChat.ENTER_EVENT, function () {
              
				console.log('BlipChat log event - enter x');
				
				if (browsingContext.Common.Shopper.IsAuthenticated) {
					console.log('Logado');
					blipClient.withAccount({
						name: browsingContext.Common.Shopper.Name,
                		fullName: browsingContext.Common.Shopper.Name + ' ' + browsingContext.Common.Shopper.SurName,
						gender: browsingContext.Common.Customer.Gender,
              			email: browsingContext.Common.Shopper.Email,
              			phoneNumber: browsingContext.Common.Customer.ExtendedProperties.Phone.Value,
                  		extras: {
                  			CustomerID: browsingContext.Common.Customer.CustomerID
                    	}
					})
					.build();
              	}
				
            })
			/**
            .withEventHandler(BlipChat.LEAVE_EVENT, function () {
              
				console.log('BlipChat log event - leave');
				
            })
            .withEventHandler(BlipChat.LOAD_EVENT, function () {
              
				console.log('BlipChat log event - loaded');
				
            })
            .withEventHandler(BlipChat.CREATE_ACCOUNT_EVENT, function () {
              	
				console.log('BlipChat log event - account created');
				
            })
            //.withCustomMessageMetadata({ "user origin" : "browser" })
            */
			;
            blipClient.build();
        //};
 })();
</script>
<style>
  #blip-chat-open-iframe { 
    bottom: 75px !important; 
  }
</style>

Mas não abre o widget:

SNV_04039_2020-02-04_17-55-09

Console do navegador:


Bruno
  • Specialist
  • 5 de fevereiro de 2020

@AndyDaSilva52

Tente desta forma:

(function () {
    window.onload = function () {
        var blipClient = undefined;
        var key = 'KEY';
        var button = { "color": "#3a183d" };

        blipClient = new BlipChat()
            .withAppKey(key)
            .withButton(button)
            .withoutHistory()
    
        if (browsingContext.Common.Shopper.IsAuthenticated) {
            blipClient.withAccount({
                name: browsingContext.Common.Shopper.Name,
                fullName: browsingContext.Common.Shopper.Name + ' ' + browsingContext.Common.Shopper.SurName,
                gender: browsingContext.Common.Customer.Gender,
                email: browsingContext.Common.Shopper.Email,
                phoneNumber: browsingContext.Common.Customer.ExtendedProperties.Phone.Value,
                extras: {
                    CustomerID: browsingContext.Common.Customer.CustomerID
                }
            })
        }

        blipClient.build();
    };
})();

Não funciona, quando entro no site IsAuthenticated está false

Essa sugestão sua não altera os dados do contato depois que IsAuthenticated está true, ou seja, após ser logado no site, pois já deve ter sido instanciado a sessão do contato! Como fazer para alterar? Não deveria blipClient.withAccount() ajustar os dados de contato?

Eu teria que resetar a sessão do contato? Mas e a conversa que já foi iniciada


Bruno
  • Specialist
  • 5 de fevereiro de 2020

Não é possível alterar os dados do usuário pelo script do blipchat depois que ele foi criado, somente na primeira interação mesmo.

Caso você precise fazer isso, será necessário fazer pelo fluxo do bot usando a ação Definir Contato.


Comente


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Definições de cookies