blip_sdk

Creator: coderz1093

Last updated:

0 purchases

blip_sdk Image
blip_sdk Images

Languages

Categories

Add to Cart

Description:

blip sdk

BLip SDK #

Simple BLiP SDK for Flutter




Read more about BLiP here
Installing #
Flutter
Simply install the blip_sdk package from the pub.dev registry, to access the BLiP server:
flutter pub add blip_sdk
copied to clipboard
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 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:
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...

copied to clipboard
Each client instance represents a server connection and can be reused. To close a connection:
final Session session = client.close().catch(function(err) { /* Disconnection failed */ });
copied to clipboard
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:
final onMessageListener = StreamController<Message>();

client.addMessageListener(onMessageListener);

onMessageListener.stream.listen((Message message) {
// Process received message
});
copied to clipboard
The next sample shows how to add a notification listener with a filter for the received event type:
final onNotificationListener = StreamController<Notification>();

client.addNotificationListener(onNotificationListener, filters: (Notification notification) => notification.event == NotificationEvent.received);

onNotificationListener.stream.listen((Notification message) {
// Process received notification
});
copied to clipboard
It's also possible to use a custom function as a filter:
Example of a message listener filtering by the originator:
final onMessageListener = StreamController<Message>();

client.addMessageListener(onMessageListener, filters: (Message message) => message.from == Node.parse('[email protected]'));

onMessageListener.stream.listen((Message message) {
// Process received message
});
copied to clipboard
Each registration of a listener returns a handler that can be used to cancel the registration:
final removeListener = client.addMessageReceiver(stream, filters: (Message message) => message.type == 'application/json');
// ...
removeListener();
copied to clipboard
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:
final Session session = await client.connect();

final msg = Message(type: 'text/plain', content: 'Hello, world', to: Node.parse('[email protected]'));
client.sendMessage(msg);
copied to clipboard
The following sample shows how to send a notification after the connection has been stablished:
final Session session = await client.connect();

// Sending a "received" notification
final notification = Notification(id: 'ef16284d-09b2-4d91-8220-74008f3a5788', to: Node.parse('[email protected]'), event: NotificationEvent.received);
client.sendNotification(notification);
copied to clipboard
Contributing #
For information on how to contribute to this package, please refer to our Contribution guidelines.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.