-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
36 lines (30 loc) · 937 Bytes
/
example.py
File metadata and controls
36 lines (30 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
from lib.wcc import WebsocketCollabClient, ProtocolMessage
WS_URL = "<url>"
USER = "<user>"
PASS = "<pass>"
CHANNEL_ID = "<channel id>"
client = WebsocketCollabClient()
client.connect(
url=WS_URL,
channel_id=CHANNEL_ID,
user=USER,
password=PASS)
def listener_text(msg: ProtocolMessage):
"""
Called when a message destined to you, and that you did not send is received
by the client.
"""
print("RAW:", msg.to_dict())
print(f"From: '{msg.payload.name}' Message: '{msg.payload.content}'")
def listener_all(msg: ProtocolMessage):
"""
Called with every message, even those you sent or those that are not destined
to you. Additional checks may be required.
"""
print("Received:", msg.to_dict())
client.on_text_message(listener_text)
client.on_all_messages(listener_all)
while True:
time.sleep(2)
client.send_text("Hilda", "This is a test message", ["all"])