Skip to content

Commit

Permalink
Merge pull request #1 from ownikss/update
Browse files Browse the repository at this point in the history
Version 0.1.0
  • Loading branch information
ownikss authored Jul 22, 2020
2 parents 1520269 + 0968919 commit a5639e3
Show file tree
Hide file tree
Showing 387 changed files with 834 additions and 48,383 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
.idea
.vscode
/js
build
*.iml
local.properties
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea
.vscode
build
*.iml
local.properties
110 changes: 79 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,106 @@
# react-native-webim
# webim-react-native

Implementation of [webim sdk](https://webim.ru/) for [react-native](https://github.com/facebook/react-native)

**Important:** last tested react-native version is 59.9
**Important:** Updated version for RN 0.60+

## Installation

```
yarn add react-native-webim
react-native link react-native-webim
yarn add webim-react-native
```

iOS:
iOS
- add to PodFile
```
use_frameworks!
pod 'WebimClientLibrary', :git => 'https://github.com/webim/webim-client-sdk-ios.git', :tag => '3.29.0'
```
- pod install

- add `Libraries/RNWebim/Libraries/WebimClientLibrary/Product/WebimClientLibrary.framework` into **Link Binary With Libraries**
- to be done
- move `WebimClientLibrary.framework` and `SQLite.framework` to **Embedded binaries**
- create empty swift file in ios project root and agree with creating bridging header.
**Note:** Flipper doesn't work with use_frameworks flag

## Usage

**Important:** All methods are promise based and can throw exceptions

- Init chat:
```js
webim.resumeSession("accountName", "location")
### Init chat

```ts
import webim from 'webim-react-native';

webim.resumeSession(builderParams)
```

```ts
type SessionBuilderParams = {
accountName: string;
location: string;
accountJSON?: string;
providedAuthorizationToken?: string;
appVersion?: string;
clearVisitorData?: boolean;
storeHistoryLocally?: boolean;
title?: string;
pushToken?: string;
};
```
- accountName (required) - name of your account in webim system
- location (required) - name of location. For example "mobile"
- accountJSON - encrypted json with user data. See **Start chat with user data**
- clearVisitorData - clear visitor data before start chat
- storeHistoryLocally - cache messages in local store
- title - title for chat in webim web panel
- providedAuthorizationToken - user token. Session will not start with wrong token. Read webim documentation
- pushToken
- appVersion


### Init events listeners

- Init events listeners:
```js
webim.addListener(webimEvents.NEW_MESSAGE, ({ msg }) => {
import webim, { WebimEvents} from 'webim-react-native';
const listener = webim.addNewMessageListener(({ msg }) => {
// do something
});
// usubscribe
listener.remove();
// or
const listener2 = webim.addListener(WebimEvents.NEW_MESSAGE, ({ msg }) => {
// do something
});
```
Supported events: `NEW_MESSAGE, REMOVE_MESSAGE, EDIT_MESSAGE, CLEAR_DIALOG`
Supported events (`WebimEvents`):
- WebimEvents.NEW_MESSAGE;
- WebimEvents.REMOVE_MESSAGE;
- WebimEvents.EDIT_MESSAGE;
- WebimEvents.CLEAR_DIALOG;
- WebimEvents.TOKEN_UPDATED;
- WebimEvents.ERROR;

### Get messages

- Get messages:
```js
const { messages } = await webim.getLastMessages(100);
const { messages } = await webim.getLastMessages(limit);
// or
const { messages } = await webim.getNextMessages(100);
const { messages } = await webim.getNextMessages(limit);
// or
const { messages } = await webim.getAllMessages();
```
Note: method `getAllMessages` works strange on iOS, and sometimes returns empty array. We recommend to use `getLastMessages` instead

- Send text message:
### Send text message

```
webim.send(message);
```
- Use build in method for file attaching:
### Attach files
#### Use build in method for file attaching:
```js
try {
await webim.tryAttachFile();
Expand All @@ -64,7 +114,8 @@ try {
}
```

- or attach files by yourself:
#### or attach files by yourself

```js
try {
webim.sendFile(uri, name, mime, extension)
Expand All @@ -73,29 +124,31 @@ try {
}
```

- rate current operator:
### Rate current operator
```js
webim.rateOperator()
```

- destroy session:
### Destroy session
```js
webim.destroySession();
webim.destroySession(clearData);
```

See `index.d.ts` for getting types information
- clearData (optional) boolean - If true wil

## Start chat with user data

See [webim documentation](https://webim.ru/kb/dev/identification/8265-id-2-0/) for client identification.

Example:

- install [react-native-crypto](https://github.com/tradle/react-native-crypto) with all dependencies and run `rn-nodeify --hack --install`
- run `rn-nodeify --hack --install` after each `npm install` (add in postinstall script)

```js
```ts
import './shim'; // set your path to shim.js
import crypto from 'crypto';

const getHmac_sha256 = (str: string, privateKey: string) => {
const hmac = crypto.createHmac('sha256', privateKey);
const promise = new Promise((resolve: (hash: string) => void) => hmac.on('readable', () => {
Expand Down Expand Up @@ -127,8 +180,3 @@ acc.hash = await getHash(acc.fields);

await webim.resumeSession('accountName', 'location', JSON.stringify(acc));
```

## TODO:

- screenshots for installation guide
- example
24 changes: 24 additions & 0 deletions RNWebim.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'RNWebim'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.author = package['author']
s.source = { :git => "https://github.com/volga-volga/react-native-webim.git", :tag => "v#{s.version}" }

s.homepage = package['repository']['url']

s.requires_arc = true
s.platform = :ios, '9.0'

s.preserve_paths = 'LICENSE', 'README.md', 'package.json', 'index.js'
s.source_files = "ios/*.{h,m,swift}"

s.dependency 'React'
s.dependency 'WebimClientLibrary'

end
Binary file added android/.gradle/4.6/fileChanges/last-build.bin
Binary file not shown.
Binary file added android/.gradle/4.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added android/.gradle/4.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added android/.gradle/5.5/fileChanges/last-build.bin
Binary file not shown.
Binary file added android/.gradle/5.5/fileHashes/fileHashes.lock
Binary file not shown.
Empty file.
Empty file.
Empty file.
29 changes: 13 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
versionName "0.0.7"
}
lintOptions {
warning 'InvalidPackage'
warning 'InvalidPackage'
}
}

allprojects {
repositories {
jcenter()
}
repositories {
mavenCentral()
}

dependencies {
implementation 'com.webimapp.sdk:webimclientsdkandroid:3.26.2'
implementation 'com.webimapp.sdk:webimclientsdkandroid:3.32.5'
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.android.gms:play-services-wallet:16.0.0'
// todo:
implementation "com.android.support:appcompat-v7:25.0.1"
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit a5639e3

Please sign in to comment.