blip-sdk-python
Simple BLiP SDK for Python
This is a work in progress
Read more about BLiP here
Installing
You should install the blip-sdk package to access the BLiP server:
pip install blip-sdk
pip install lime-transport-websocket
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 scratchmodel option; - Go to Settings and click in Connection Information;
- Get your bot's
identifierandaccess key.
In order to instantiate the client use the ClientBuilder class informing the identifier and access key
You can start the client asynchronously or synchronously
Asynchronously (the recommended way)
import asyncio
from lime_transport_websocket import WebSocketTransport
from blip_sdk import ClientBuilder
async def main_async() -> None:
# Create a client instance passing the identifier and access key of your chatbot
client = ClientBuilder() \
.with_identifier(IDENTIFIER) \
.with_access_key(ACCESS_KEY) \
.with_transport_factory(lambda: WebSocketTransport()) \
.build()
# Connect with the server asynchronously
# Connection will occurr via websocket on the 8081 port
await client.connect_async()
print('Application started. Press Ctrl + c to stop.')
loop = asyncio.get_event_loop()
loop.run_until_complete(main_async())
loop.run_forever()
Or the sync version (we only recommend for scripts)
from time import sleep
from lime_transport_websocket import WebSocketTransport
from blip_sdk import ClientBuilder
def main() -> None:
# Create a client instance passing the identifier and access key of your chatbot
client = ClientBuilder() \
.with_identifier(IDENTIFIER) \
.with_access_key(ACCESS_KEY) \
.with_transport_factory(lambda: WebSocketTransport()) \
.build()
# Connect with the server asynchronously
# Connection will occurr via websocket on the 8081 port
client.connect()
print('Application started. Press Ctrl + c to stop.')
main()
while True:
sleep(1)
Each client instance represents a server connection and can be reused. To close a connection:
await client.close_async()
# or sync
client.close()
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:
client.add_message_receiver(Receiver(True, lambda m: print(m)))
The next sample shows how to add a notification receiver with a filter for the received event type:
client.add_notification_receiver(Receiver(lambda n: n.event == NotificationEvent.RECEIVED, lambda n: print(n)))
It's also possible to use a custom function as a filter:
Example of a message receiver filtering by the originator:
def filter_originator(message: Message) -> bool:
return message.from_n == '553199990000@0mn.io'
client.add_message_receiver(Receiver(filter_originator, lambda m: print(m)))
Each registration of a receiver returns a handler that can be used to cancel the registration:
remove_receiver = client.add_message_receiver(Receiver(True, lambda m: print(m)))
remove_receiver()
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:
await client.connect_async()
# Once connected it's possible to send messages
message = client.send_message(Message('text/plain', 'message', to=user_id))
The following sample shows how to send a notification after the connection has been stablished:
client.connect_async()
notification = Notification(
NotificationEvent.Received,
Reason(ReasonCode.ApplicationError, 'failed'),
to=user_Id
)
client.send_notification(notiication)
Contributing
For information on how to contribute to this package, please refer to our Contribution guidelines.
Metadata
Release files for blip-sdk 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| blip_sdk-1.0.4.tar.gz | 22.1 kB | Without provenance | Details for blip_sdk-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blip_sdk-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for blip_sdk-1.0.4-py3-none-any.whl |
Total release size: 58.1 kB
Release files / blip_sdk-1.0.4.tar.gz
| Download URL | blip_sdk-1.0.4.tar.gz |
|---|---|
| Size | 22.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e24c1dbeb5e0feb0e56224ef06d5d7822569ae0d57a1dc70a37c4954082fcd02
|
|
BLAKE2b-256 checksum How to use checksums |
af88318bf1682a8f207886da183799c3c6bf7983b8dd628d8415f9f09f4f10ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
|
Release files / blip_sdk-1.0.4-py3-none-any.whl
| Download URL | blip_sdk-1.0.4-py3-none-any.whl |
|---|---|
| Size | 36.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ceb0b6e96ee474e7e0ea5d39c3bf1d1caf05fc5a7e7eae61c14219c0e1cb7d0
|
|
BLAKE2b-256 checksum How to use checksums |
7e4da97d34fb2b343ea480d2d6225fc6a48eea189ed289b2fc1b8d373b76bdee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
|
Security for blip-sdk 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.