# react-native-chatvt

Chat VT SDK

## Installation

```sh
npm install react-native-chatvt
```



## VTPost

```js
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

```js
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
```js
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',
      'eyJhbGciOiJSUzI1NiIsImtpZCI6IjEzODFCMzg2OUFGRDlBRTU4NDYwREY0M0VENEZGQkE5NzhFNzg3QTQiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJFNEd6aHByOW11V0VZTjlEN1VfN3FYam5oNlEifQ. .y23RaKyA3JIdU4Oq4fsbWeD-BGG0zz4n4FbmNT7GCEXybi9YmZ7khInAygovKrbPvWncAjM7qfyIfzuzvJ24ZZmMJWpex9vONwPywE_4yMdcx6xckI7VOLNZPqCpu9-TGj03cj8srzeqI7Y_hKTezhOcLD0RWxIsRkJwcyg6a3b9s5uesW2CmBHYSxO2hbB5X2FQRlEjABje2keNxqwj5R7kZX13C6J_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

```js
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. .BW7UAD8ecYVDywNhRjIAhXSy5pGqcfWvtf19EeNkJnE',
      ''
      , () => {
        setAuth(true)
      })


  })

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



```


## License

MIT

---
