Python API wrapper for Rocket.Chat's REST API, enabling developers to programmatically interact with Rocket.Chat servers for chat automation, bot development, and integration purposes
—
Customer support and live chat functionality for external visitor engagement. Provides tools for visitor management, inquiry handling, agent assignment, and customer service workflows.
def livechat_register_visitor(self, token, **kwargs):
"""
Register a new livechat visitor.
Parameters:
- token (str): Visitor token
- name (str, optional): Visitor name
- email (str, optional): Visitor email
- department (str, optional): Department ID
- phone (str, optional): Phone number
- customFields (dict, optional): Custom visitor fields
Returns:
requests.Response: Visitor registration result
"""
def livechat_get_visitor(self, token):
"""
Get visitor information.
Parameters:
- token (str): Visitor token
Returns:
requests.Response: Visitor information
"""def livechat_room(self, token, **kwargs):
"""
Get livechat room or create new session.
Parameters:
- token (str): Visitor token
- rid (str, optional): Existing room ID
- agentId (str, optional): Specific agent ID
Returns:
requests.Response: Room information
"""
def livechat_rooms(self, **kwargs):
"""
List livechat rooms.
Parameters:
- agents (list, optional): Filter by agent IDs
- departmentId (str, optional): Filter by department
- open (bool, optional): Filter by open status
- createdAt (dict, optional): Date range filter
- closedAt (dict, optional): Date range filter
- tags (list, optional): Filter by tags
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
- sort (dict, optional): Sort criteria
Returns:
requests.Response: List of livechat rooms
"""def livechat_message(self, token, rid, msg, **kwargs):
"""
Send livechat message.
Parameters:
- token (str): Visitor token
- rid (str): Room ID
- msg (str): Message text
- agent (dict, optional): Agent information
- file (dict, optional): File attachment
Returns:
requests.Response: Message sending result
"""
def livechat_messages_history(self, rid, token, **kwargs):
"""
Get livechat message history.
Parameters:
- rid (str): Room ID
- token (str): Visitor token
- end (str, optional): End date
- limit (int, optional): Message limit
- ls (str, optional): Last seen timestamp
Returns:
requests.Response: Message history
"""def livechat_inquiries_list(self, **kwargs):
"""
List open livechat inquiries.
Parameters:
- department (str, optional): Filter by department
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
- sort (dict, optional): Sort criteria
Returns:
requests.Response: List of inquiries
"""
def livechat_inquiries_take(self, inquiry_id, **kwargs):
"""
Take/assign an inquiry to current agent.
Parameters:
- inquiry_id (str): Inquiry ID to take
- userId (str, optional): Agent user ID
Returns:
requests.Response: Assignment result
"""def livechat_get_users(self, user_type, **kwargs):
"""
Get livechat agents or managers.
Parameters:
- user_type (str): User type ('agent' or 'manager')
- offset (int, optional): Number of items to skip
- count (int, optional): Number of items to return
Returns:
requests.Response: List of users
"""
def livechat_create_user(self, user_type, **kwargs):
"""
Create livechat agent or manager.
Parameters:
- user_type (str): User type ('agent' or 'manager')
- username (str): Username
- email (str): Email address
- name (str): Full name
Returns:
requests.Response: User creation result
"""
def livechat_get_user(self, user_type, user_id, **kwargs):
"""
Get livechat agent or manager information.
Parameters:
- user_type (str): User type ('agent' or 'manager')
- user_id (str): User ID
Returns:
requests.Response: User information
"""
def livechat_delete_user(self, user_type, user_id):
"""
Delete livechat agent or manager.
Parameters:
- user_type (str): User type ('agent' or 'manager')
- user_id (str): User ID to delete
Returns:
requests.Response: Deletion result
"""VisitorObject = {
"_id": "str", # Visitor ID
"token": "str", # Visitor token
"name": "str", # Visitor name
"email": "str", # Visitor email
"phone": "str", # Phone number
"department": "str", # Department ID
"customFields": "dict", # Custom fields
"userAgent": "str", # Browser user agent
"ip": "str", # IP address
"createdAt": "datetime" # Registration timestamp
}
LiveChatRoomObject = {
"_id": "str", # Room ID
"fname": "str", # Room display name
"t": "str", # Room type ('l' for livechat)
"v": "VisitorObject", # Visitor information
"servedBy": "UserObject", # Assigned agent
"departmentId": "str", # Department ID
"open": "bool", # Room open status
"tags": ["str"], # Room tags
"createdAt": "datetime", # Creation timestamp
"closedAt": "datetime", # Close timestamp
"lastMessage": "MessageObject", # Last message
"metrics": { # Room metrics
"chatDuration": "int",
"responseTime": "dict"
}
}
InquiryObject = {
"_id": "str", # Inquiry ID
"rid": "str", # Room ID
"name": "str", # Visitor name
"email": "str", # Visitor email
"subject": "str", # Inquiry subject
"department": "str", # Department ID
"message": "str", # Initial message
"status": "str", # Inquiry status
"ts": "datetime", # Timestamp
"agents": ["str"], # Available agents
"locked": "bool", # Lock status
"lockedBy": "UserObject" # Locked by agent
}# Register a new visitor
visitor_token = "unique_visitor_token"
visitor_response = rocket.livechat_register_visitor(
token=visitor_token,
name="John Customer",
email="john@example.com",
customFields={"source": "website"}
)
# Create or get livechat room
room_response = rocket.livechat_room(token=visitor_token)
room_id = room_response.json()['room']['_id']
# Send a message from visitor
rocket.livechat_message(
token=visitor_token,
rid=room_id,
msg="Hello, I need help with my account"
)
# Agent takes an inquiry
inquiries = rocket.livechat_inquiries_list()
if inquiries.json()['inquiries']:
inquiry_id = inquiries.json()['inquiries'][0]['_id']
rocket.livechat_inquiries_take(inquiry_id)
# Get message history
history = rocket.livechat_messages_history(room_id, visitor_token)Install with Tessl CLI
npx tessl i tessl/pypi-rocketchat-a-p-i