View Categories

Guía completa para instalar WhatChat en tu aplicación React Native

Si tienes una aplicación de React Native, puedes integrar el widget de chat en vivo de WhatChat y comunicarte con tus visitantes en tiempo real. Esto se puede realizar en 3 sencillos pasos utilizando el plugin de WhatChat.

Paso 1. Crea un buzón de sitio web en WhatChat #

Consulta esta guía para obtener instrucciones detalladas sobre cómo configurar un buzón en WhatChat.

Paso 2. Agrega el plugin a tu proyecto #

Agrega uno de los siguientes plugins a tu proyecto:

yarn add @whatchat/react-native-widget

o

npm install --save @whatchat/react-native-widget --save

Esta biblioteca depende de react-native-webview y async-storage. Por favor, sigue las instrucciones proporcionadas en la documentación.

Instalación en iOS

Si estás utilizando versiones de React Native mayores a 60.0, es bastante sencillo.

cd ios && pod install

Paso 3. Utilízalo de esta forma #

Reemplaza websiteToken y baseUrl con los valores apropiados.

import React, { useState } from 'react';
import { StyleSheet, View, SafeAreaView, TouchableOpacity, Text } from 'react-native';
import WhatChatWidget from '@whatchat/react-native-widget';

const App = () => {
  const [showWidget, toggleWidget] = useState(false);
  const user = {
    identifier: 'john@gmail.com',
    name: 'John Samuel',
    avatar_url: '',
    email: 'john@gmail.com',
    identifier_hash: '',
  };
  const customAttributes = { accountId: 1, pricingPlan: 'paid', status: 'active' };
  const websiteToken = 'WEBSITE_TOKEN';
  const baseUrl="WHATCHAT_INSTALLATION_URL";
  const locale="es";

  return (
    <SafeAreaView style={styles.container}>
      <View>
        <TouchableOpacity style={styles.button} onPress={() => toggleWidget(true)}>
          <Text style={styles.buttonText}>Abrir widget</Text>
        </TouchableOpacity>
      </View>
      {
        showWidget&&
          <WhatChatWidget
            websiteToken={websiteToken}
            locale={locale}
            baseUrl={baseUrl}
            closeModal={() => toggleWidget(false)}
            isModalVisible={showWidget}
            user={user}
            customAttributes={customAttributes}
          />
      }

    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },

  button: {
    height: 48,
    marginTop: 32,
    paddingTop: 8,
    paddingBottom: 8,
    backgroundColor: '#1F93FF',
    borderRadius: 8,
    borderWidth: 1,
    borderColor: '#fff',
    justifyContent: 'center',
  },
  buttonText: {
    color: '#fff',
    textAlign: 'center',
    paddingLeft: 10,
    fontWeight: '600',
    fontSize: 16,
    paddingRight: 10,
  },
});

export default App;

Y… ¡eso es todo! Consulta el ejemplo completo aquí.