@chatwoot/react-native-widget

中文文档
0.0.21发布于 2024/10/14MITTypeScriptCommonJS近 30 天下载 3万

React Native widget for Chatwoot

原始使用文档
文档目录5 节
  1. Installation
  2. iOS Installation
  3. How to use
  4. Props
  5. Feedback & Contributing

chatwoot-react-native-widget

PRs Welcome

  • Supported Chatwoot version: 2.16.0+
screenshot

Installation

Install the library using either yarn or npm like so:

yarn add @chatwoot/react-native-widget

OR

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

This library depends on react-native-webview and async-storage. Please follow the instructions provided in the docs.

iOS Installation

If you're using React Native versions > 60.0, it's relatively straightforward.

cd ios && pod install

How to use

  1. Create a website channel in chatwoot server by following the steps described here https://www.chatwoot.com/docs/channels/website
  2. Replace websiteToken prop and baseUrl

import React, { useState } from 'react';

import { StyleSheet, View, SafeAreaView, TouchableOpacity, Text } from 'react-native';

import ChatWootWidget from '@chatwoot/react-native-widget';

const App = () => {
  const [showWidget, toggleWidget] = useState(false);
  const user = {
    identifier: '[email protected]',
    name: 'John Samuel',
    avatar_url: '',
    email: '[email protected]',
    identifier_hash: '',
  };
  const customAttributes = { accountId: 1, pricingPlan: 'paid', status: 'active' };
  const websiteToken = 'WEBSITE_TOKEN';
  const baseUrl = 'CHATWOOT_INSTALLATION_URL';
  const locale = 'en';
  const colorScheme='dark'

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

    </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;

You're done!

The whole example is in the /example folder.

Props

NameDefaultTypeDescription
baseUrl - String Chatwoot installation URL
websiteToken - String Website channel token
colorScheme light String Widget color scheme (light/dark/auto)
locale en String Locale
isModalVisible false Boolean Widget is visible or not
closeModal - Function Close event
user {} Object User information about the user like email, username and avatar_url
customAttributes {} Object Additional information about the customer

Feedback & Contributing

Feel free to send us feedback on Twitter or file an issue.

If there's anything you'd like to chat about, please feel free to join our Discord chat!

Chatwoot © 2017-2023, Chatwoot Inc - Released under the MIT License.

版本与发布记录

@chatwoot/react-native-widget 共发布 19 个版本,首次发布于 2021/03/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.21latest2024/10/142 年前
0.0.202024/09/272 年前
0.0.192024/09/042 年前
0.0.182023/08/093 年前
0.0.172023/08/083 年前
0.0.162023/08/023 年前

关于 @chatwoot/react-native-widget 的常见问题

@chatwoot/react-native-widget 是什么?

React Native widget for Chatwoot

如何安装 @chatwoot/react-native-widget?

在项目目录运行 npm install @chatwoot/react-native-widget,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@react-native-async-storage/async-storage(>=1.23.1)、react(*)、react-native(*)、react-native-webview(>=13.8.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@chatwoot/react-native-widget 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chatwoot/react-native-widget 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@chatwoot/react-native-widget 可以商用吗?

@chatwoot/react-native-widget 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chatwoot/react-native-widget 的下载量有多少?

根据 npm 官方下载统计,@chatwoot/react-native-widget 在 2026/10/10 – 2026/11/08 这 30 天内被下载 29,696 次,日均约 990 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chatwoot/react-native-widget 还在维护吗?

最新版本 0.0.21 发布于 2024/10/14(2 年前);至今共发布 19 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。