1.1.52 • Published 2 months ago

react-native-chatvt v1.1.52

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

react-native-chatvt

Chat VT SDK

Installation

npm install react-native-chatvt

VTPost

import {chatVT}  from 'react-native-chatvt';
import AsyncStorage from "@react-native-async-storage/async-storage";

chatVT.init(env, AsyncStorage, lang, appId,  token, tokenSSO, onSuccess?, onError?)

// appId:  "VTMan", "VTPost"
// env: môi trường  "DEV", "UAT", "PRODUCT"
// lang là ngôn ngữ enum('VN', 'EN')
// token, token_sso:  do bên Viettel Posst cung cấp

Ví dụ VTPost

import {chatVT}  from 'react-native-chatvt';
import AsyncStorage from "@react-native-community/async-storage";

chatVT.init(env, AsyncStorage, lang, appId,  token, tokenSSO, onSuccess?, onError?)

// appId:  "VTMan", "VTPost"
// env: môi trường  "DEV", "UAT", "PRODUCT"
// lang là ngôn ngữ enum('VN', 'EN')
// token, token_sso:  do bên Viettel Posst cung cấp

Ví dụ VTPost

import {chatVT}  from 'react-native-chatvt';
import AsyncStorage from "@react-native-async-storage/async-storage";//<- chú ý thư viện 2 app khác nhau

export default function App(props: any) {
  const AppId = "VTPost"

  const [auth, setAuth] = useState(false)

  useEffect(() => {
    chatVT.init(
      "DEV",
      AsyncStorage,
      "VN",
      AppId,
      'eyJhbGciOiJFUzI1NiJ9.eyJzdWIiOiIwMzI3NDk3OTk2IiwiU1NPSWQiOiJkZmMxYmFjYy1jNjE4LTRkNDctOTBhZS1jZDRmMTMzMDNmM2MiLCJVc2VySWQiOjcyNDEyOTgsIkZyb21Tb3VyY2UiOjMsIlRva2VuIjoiNEU2QzAyRUVGODU4MkYxNDMwMkU1Q0NBMEM1MjEzMDkiLCJleHAiOjE3MTg1MjY2NDEsIlBhcnRuZXIiOjY5MzU5MzF9.4hvyYpPN6ABdGXi0Imjoqi18Luxo9xokg7GFPT_iczfqSEQ-VXzG-KCjL__SB5O77ZU1SohGEOvxbMpgXEQoMA',
      'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEzODF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3b9s5uesW2CmBHYSxO2hbB5X2FQRlEjABje2keNxqwj5R7kZX13C6J_0JvdV9DPtE_aSHkM5kW3M5elOQq6Z7E48xHHQF3gM1y5AWuPquBeg_AO05sfBRxUlzMjYdHTjn0isZ7BPJlCQXMaUP_kFYRQmjkkEZpx5dFdgVZK8FaO2Q'
      , () => {
        setAuth(true)
      })

  })

  return (<>
      {
        auth?
          <SafeAreaView style={{padding: 16}}>
            <Button
              onPress={(() => {
                /** Mở màn hình danh sách chat */
                chatVT.toListChat(props.componentId)
              })}
              title={'List chat'}>

            </Button>
            <View style={{height: 16}}/>
            <Button
              onPress={(() => {

                /** VTP tạo chat với bưu tá */
                chatVT.toChat(props.componentId, {
                  /** vtm_user_ids: mảng gồm id của bưu tá */
                  /** order_number: mã vận đơn */
                  vtm_user_ids: [
                    985979
                  ],
                  order_number: '1694287621393'
                })


                // /** VTM tạo chat với khách hàng */
                // chatVT.toChat(props.componentId, {
                //   /** vtm_user_ids: mảng gồm id của bưu tá */
                //   /** order_number: mã vận đơn */
                //   vtp_user_ids: [
                //     985979
                //   ],
                //   order_number: '1694287621393'
                // })
              })}
              title={'Chat Detail'}>

            </Button>
          </SafeAreaView>
          :
          <Text> Đang xác thực tài khoản</Text>
      }
    </>
  )
}

Ví dụ VTMan

import {chatVT}  from 'react-native-chatvt';
import AsyncStorage from "@react-native-community/async-storage"; //<- chú ý thư viện 2 app khác nhau

export default function App(props: any) {
  const AppId = "VTMan"

  const [auth, setAuth] = useState(false)

  useEffect(() => {
    chatVT.init(
      "DEV",
      AsyncStorage,
      "VN",
      AppId,
      'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI5ODU5NzkiLCJ1c2VybmFtZSI6Im5ndW9udGVzdDEiLCJtYV9idXVjdWMiOiJUTjIiLCJuYW1lIjoiVGVzdCAxIiwicGhvbmUiOiI4NDM4ODAyMjA3MSIsImRvbl92aSI6IlRDVCIsIm1hX2NodWNkYW5oIjoiVlRCMDA5IiwiaXNzIjoiLTEwIiwiZW1wbG95ZWVfZ3JvdXBfaWQiOiI0Iiwic291cmNlIjoiLTEwIiwic291cmNlMiI6IiIsInRva2VuIjoiZWE4MGY3MmMtYmNmYy00OGRmLTk1NWMtMTM1ZmY2NDgzMWU1IiwidG9rZW4yIjoiIiwiY2FwX2J1dWN1YyI6IjUwIiwibG9ja19kdCI6IjAiLCJtYW5oYW52aWVuIjoiSTI3MDQxNzIyIiwiY2hpX25oYW5oIjoiVENUIiwidnVuZyI6IjEyIiwiZXhwIjoiMTY4ODAzOTM5MDk4MSIsImRuX3VzZXJpZCI6IjMxNjgyIn0.BW7UAD8ecYVDywNhRjIAhXSy5pGqcfWvtf19EeNkJnE',
      ''
      , () => {
        setAuth(true)
      })


  })

  return (<>
      {
        auth?
          <ListChat {...props} buttonBack={false}/>
          :
          <Text> Đang xác thực tài khoản</Text>
      }
    </>
  )
}

BottomSheetChat

Với app VTPost và Đơn nhận VTMan

// BottomSheet hiển thị options chat với ngừoi gửi, nhận, bưu tá gửi, bưu tá nhận

import {BottomSheetChat}  from 'react-native-chatvt';

export default function MyScreen() {

  const bottomSheetChatRef = useRef();

  const onMessage = ()=>{
      // Cập nhật thông tin đơn hàng đã chọn vào BottomSheet
       bottomSheetChatRef?.current?.updateData(
        //Danh sách bưu tá
        res,
        //Chi tiết đơn hàng
        orderSelected,
        //Tab Đơn gửi hay đơn nhận
        tabSelected,
        // Đơn gửi hay đơn nhận SENDER/RECEIVER
        'SENDER'
      );
      // Hiện Bottomsheet
      bottomSheetChatRef.current?.present();

  }
  ...

 return(
  <View>
    ...
    <BottomSheetChat
          // ref
          ref={bottomSheetChatRef}
          // Navigation componentId
          componentId={props.componentId}
        />
  </View>
 )

}

Với app VTMan đơn nhận

// BottomSheet hiển thị options chat với ngừoi gửi, nhận, bưu tá gửi, bưu tá nhận

import {BottomSheetChatVTM} from 'react-native-chatvt';

export default function MyScreen() {

  const bottomSheetChatRef = useRef();

  const onMessage = ()=>{
      // Cập nhật thông tin đơn hàng đã chọn vào BottomSheet
      bottomSheetChatRef?.current?.updateData(
        //Danh sách bưu tá
        res,
        //Chi tiết đơn hàng
        orderSelected,
        //Tab Đơn gửi hay đơn nhận 4 / 1
        tabSelected,
        // Đơn gửi hay đơn nhận SENDER/RECEIVER
        'SENDER'
      );
      // Hiện Bottomsheet
      bottomSheetChatRef.current?.present();
  }
  ...

 return(
  <View>
    ...
    <BottomSheetChatVTM
              // Navigation ComponentId
              componentId={this.props.parentComponentId}
              // ref
              ref={(ref) => (this.bottomSheetChatRef = ref)} />
  </View>
 )

}

Xử lý notification

Với app VTPost

import {chatVT}  from 'react-native-chatvt';

 const chatProcess = (data) => {
  try {
    // Lấy ref từ data của thông báo
    const { ref } = data;
    let eToken = UserData?.userInfo?.tokenKey;
    let sToken = UserData?.userInfo?.tokenSSO;
    chatVT.handleNotification(
      'DEV',
      AsyncStorage,
      'VN',
      'VTPost',
      eToken,
      sToken,
      () => {},
      () => {},
      //Navigation componentId
      StackScreen.componentId,
      //Conversation Id lọc từ ref
      ref?.replace('group:', ''),
    );
  } catch (error) {
    console.log(error);
  }
};

Với app VTMan

import {chatVT}  from 'react-native-chatvt';


  chatVT.handleNotification(
        "DEV",
        AsyncStorage,
        "VN",
        "VTMan",
        TKModelData.tokenVTMan,
        '',
        () => {},
        () => {},
        // Navigation componentId
        TKModelData.last_componentid,
        // Conversation Id lọc từ dữ liệu noitification
        data?.additionalProp1
      );

License

MIT


1.1.52

2 months ago

1.1.51

2 months ago

1.1.50

3 months ago

1.1.49

3 months ago

1.1.48

3 months ago

1.1.46

3 months ago

1.1.45

4 months ago

1.1.43

4 months ago

1.1.41

4 months ago

1.1.39

4 months ago

1.1.38

4 months ago

1.1.33

4 months ago

1.1.31

4 months ago

1.1.37

4 months ago

1.1.35

4 months ago

1.1.29

4 months ago

1.1.27

4 months ago

1.1.25

4 months ago

1.1.23

5 months ago

1.1.9

6 months ago

1.1.7

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.2

6 months ago

1.1.12

5 months ago

1.1.10

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.13

5 months ago

1.1.19

5 months ago

1.1.18

5 months ago

1.1.17

5 months ago

1.1.22

5 months ago

1.1.21

5 months ago

1.1.20

5 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.29

6 months ago

1.0.28

6 months ago

1.0.27

6 months ago

1.0.31

6 months ago

1.0.30

6 months ago

1.0.34

6 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.15

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

0.1.143

8 months ago

0.1.142

8 months ago

0.1.144

8 months ago

0.1.141

8 months ago

1.0.5

7 months ago

1.0.3

7 months ago

0.1.139

8 months ago

0.1.137

8 months ago

0.1.135

8 months ago

0.1.134

8 months ago

0.1.133

8 months ago

0.1.132

8 months ago

0.1.131

8 months ago

0.1.130

8 months ago

0.1.129

8 months ago

0.1.128

8 months ago

0.1.126

8 months ago

0.1.125

8 months ago

0.1.124

8 months ago

0.1.123

8 months ago

0.1.122

8 months ago

0.1.121

8 months ago

0.1.120

8 months ago

0.1.119

8 months ago

0.1.118

8 months ago

0.1.117

9 months ago

0.1.116

9 months ago

0.1.115

9 months ago

0.1.114

9 months ago

0.1.113

9 months ago

0.1.112

9 months ago

0.1.111

9 months ago

0.1.110

9 months ago

0.1.109

9 months ago

0.1.108

9 months ago

0.1.107

9 months ago

0.1.106

9 months ago

0.1.105

9 months ago

0.1.104

9 months ago

0.1.103

9 months ago

0.1.102

9 months ago

0.1.101

9 months ago

0.1.100

9 months ago

0.1.99

9 months ago

0.1.98

9 months ago

0.1.97

9 months ago

0.1.96

9 months ago

0.1.95

9 months ago

0.1.94

9 months ago

0.1.93

9 months ago

0.1.92

9 months ago

0.1.91

9 months ago

0.1.90

9 months ago

0.1.89

9 months ago

0.1.88

9 months ago

0.1.87

9 months ago

0.1.86

9 months ago

0.1.85

9 months ago

0.1.84

9 months ago

0.1.83

9 months ago

0.1.82

9 months ago

0.1.81

9 months ago

0.1.80

9 months ago

0.1.79

9 months ago

0.1.78

9 months ago

0.1.77

9 months ago

0.1.76

9 months ago

0.1.75

9 months ago

0.1.74

9 months ago

0.1.72

9 months ago

0.1.71

9 months ago

0.1.70

9 months ago

0.1.68

9 months ago

0.1.67

9 months ago

0.1.66

9 months ago

0.1.65

9 months ago

0.1.64

9 months ago

0.1.63

9 months ago

0.1.62

9 months ago

0.1.61

9 months ago

0.1.60

9 months ago

0.1.59

10 months ago

0.1.58

10 months ago

0.1.57

10 months ago

0.1.56

10 months ago

0.1.55

10 months ago

0.1.54

10 months ago

0.1.53

10 months ago

0.1.52

10 months ago

0.1.51

10 months ago

0.1.50

10 months ago

0.1.49

10 months ago

0.1.48

10 months ago

0.1.47

10 months ago

0.1.46

10 months ago

0.1.45

10 months ago

0.1.43

10 months ago

0.1.42

10 months ago

0.1.41

10 months ago

0.1.40

10 months ago

0.1.39

10 months ago

0.1.38

10 months ago

0.1.37

10 months ago

0.1.34

10 months ago

0.1.33

10 months ago

0.1.32

10 months ago

0.1.31

10 months ago

0.1.30

10 months ago

0.1.29

10 months ago

0.1.28

10 months ago

0.1.27

10 months ago

0.1.26

10 months ago

0.1.25

10 months ago

0.1.24

10 months ago

0.1.23

10 months ago

0.1.22

10 months ago

0.1.21

10 months ago

0.1.20

10 months ago

0.1.19

10 months ago

0.1.18

11 months ago

0.1.17

11 months ago

0.1.16

11 months ago

0.1.15

11 months ago

0.1.14

11 months ago

0.1.13

11 months ago

0.1.12

11 months ago

0.1.11

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.1

11 months ago