Skip to content

Commit

Permalink
readme fix
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardo.gabriel committed Mar 4, 2022
1 parent dce0a0a commit 6f1e39e
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
* Created project structure
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Contribution guidelines

## For your development environment

Install [editorconfig](http://editorconfig.org/) [plugin](http://editorconfig.org/#download)
for your ide/editor.

## Before your pull request

- Fire an issue
- Be sure to have tests

24 changes: 7 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
MIT License
Copyright 2022, CURUPIRA SA. All rights reserved.

Copyright (c) 2022 Take Blip
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141 changes: 116 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,130 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
# BLip SDK

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
> Simple BLiP SDK for Flutter
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
**This is a work in progress**

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
[![pub version](https://img.shields.io/pub/v/blip-sdk.svg)](https://pub.dev/packages/blip-sdk)
[![Test Status](https://github.com/takenet/blip-sdk-dart/actions/workflows/tests.yml/badge.svg)](https://github.com/takenet/blip-sdk-dart/actions)

## Features
---

TODO: List what your package can do. Maybe include images, gifs, or videos.
Read more about BLiP [here](http://blip.ai/)

## Getting started
### Installing

TODO: List prerequisites and provide or point to information on how to
start using the package.
#### Flutter

## Usage
Simply install the `blip_sdk` package from the [pub.dev](pub.dev) registry, to access the BLiP server:

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
flutter pub add blip_sdk

### Instantiate the BlipSdk Client

You will need an `identifier` and an `access key` to connect a chatbot to **BLiP**. To get them:

- Go to [Painel BLiP](http://portal.blip.ai/) and login;
- Click **Create chatbot**;
- Choose the `Create from scratch` model option;
- Go to **Settings** and click in **Connection Information**;
- Get your bot's `identifier` and `access key`.

In order to instantiate the client use the `ClientBuilder` class informing the `identifier` and `access key`:

```dart
import 'package:blip_sdk/blip_sdk.dart';
// Create a client instance passing the identifier and access key of your chatbot
final client = ClientBuilder(transport: WebSocketTransport())
.withIdentifier(IDENTIFIER)
.withAccessKey(ACCESS_KEY)
.build();
// Connect with the server asynchronously
// Connection will occurr via websocket on the 8081 port
final Session session = await client.connect().catch((err) { /* Connection failed */ });
/// session.state...
```

Each `client` instance represents a server connection and can be reused. To close a connection:

```dart
final Session session = client.close().catch(function(err) { /* Disconnection failed */ });
```

### Receiving

All messages sent to the chatbot are redirected to registered `receivers` of messages and notifications. You can define filters to specify which envelopes will be handled by each receiver.
The following example shows how to add a simple message receiver:

```dart
final onMessageListener = StreamController<Message>();
client.addMessageListener(onMessageListener);
onMessageListener.stream.listen((Message message) {
// Process received message
});
```

The next sample shows how to add a notification listener with a filter for the `received` event type:

```dart
const like = 'sample';
final onNotificationListener = StreamController<Notification>();
client.addNotificationListener(onNotificationListener, filters: (Notification notification) => notification.event == NotificationEvent.received);
onNotificationListener.stream.listen((Notification message) {
// Process received notification
});
```

It's also possible to use a custom function as a filter:

Example of a message listener filtering by the originator:

```dart
final onMessageListener = StreamController<Message>();
client.addMessageListener(onMessageListener, filters: (Message message) => message.from == Node.parse('553199990000@0mn.io'));
onMessageListener.stream.listen((Message message) {
// Process received message
});
```

Each registration of a listener returns a `handler` that can be used to cancel the registration:

```dart
final removeListener = client.addMessageReceiver(stream, filters: (Message message) => message.type == 'application/json');
// ...
removeListener();
```

### Sending

It's possible to send notifications and messages only after the session has been stablished.

The following sample shows how to send a message after the connection has been stablished:

```dart
final Session session = await client.connect();
final msg = Message(type: 'text/plain', content: 'Hello, world', to: Node.parse('553199990000@0mn.io'));
client.sendMessage(msg);
```

The following sample shows how to send a notification after the connection has been stablished:

```dart
final Session session = await client.connect();
// Sending a "received" notification
final notification = Notification(id: 'ef16284d-09b2-4d91-8220-74008f3a5788', to: Node.parse('553199990000@0mn.io'), event: NotificationEvent.received);
client.sendNotification(notification);
```

## Additional information
## Contributing

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
For information on how to contribute to this package, please refer to our [Contribution guidelines](https://github.com/takenet/blip-sdk-dart/blob/master/CONTRIBUTING.md).
29 changes: 25 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,24 @@ packages:
lime:
dependency: "direct main"
description:
path: "../lime-dart"
relative: true
source: path
version: "0.0.1"
name: lime
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.3"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
matcher:
dependency: transitive
description:
Expand All @@ -109,6 +116,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pretty_json:
dependency: transitive
description:
name: pretty_json
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
simple_logger:
dependency: transitive
description:
name: simple_logger
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: blip_sdk
description: A new Flutter package project.
description: Simple BLiP SDK for Dart
version: 0.0.1
homepage:
homepage: https://github.com/takenet/blip-sdk-dart#readme
repository: https://github.com/takenet/lime-dart

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -10,8 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
lime:
path: ../lime-dart/
lime: ^0.0.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 6f1e39e

Please sign in to comment.