def fetch_messages(chatkit_access_data, room_id, initial_id=None, limit=20, direction="newer"): """ direction in ['newer', 'older'] """ endpoint_parts = ["rooms", room_id, "messages"] query_parameters = {} if (initial_id is not None): query_parameters['initial_id'] = initial_id if (limit is not None): query_parameters['limit'] = limit if (direction is not None): query_parameters['direction'] = direction return base.chatkit_request(chatkit_access_data, endpoint_parts, method="GET", query_parameters=query_parameters)
def leave_room(chatkit_access_data, room_id, user_id): endpoint_parts = ['users', user_id, 'rooms', room_id, 'leave'] parameters = { } return base.chatkit_request(chatkit_access_data, endpoint_parts, method="POST", json_parameters=parameters)
def remove_users(chatkit_access_data, room_id, user_ids=[]): endpoint_parts = ['rooms', room_id, 'users', 'remove'] parameters = { "user_ids": user_ids } return base.chatkit_request(chatkit_access_data, endpoint_parts, method="PUT", json_parameters=parameters)
def fetch_rooms(chatkit_access_data, from_id=None, include_private=False): endpoint_parts=['rooms'] query_parameters = {} if(from_id is not None): query_parameters['from_id'] = from_id if(include_private is not None): query_parameters['include_private'] = 'true' if bool(include_private) else 'false' return base.chatkit_request(chatkit_access_data, endpoint_parts, method='GET', query_parameters=query_parameters)
def typing_indicators(chatkit_access_data, room_id, start=True, data={}): endpoint_parts = ["rooms", room_id, "events"] parameters = { "name": "typing_start" if (bool(start) is True) else "typing_stop" } if (data not in [[], {}]): parameters['data'] = data return base.chatkit_request(chatkit_access_data, endpoint_parts, method="POST", json_parameters=parameters)
def update_room(chatkit_access_data, room_id, name=None, private=None, custom_data=None): parameters = {} endpoint_parts = ['rooms', room_id] if(name is not None): parameters['name'] = name if(private is not None): parameters['private'] = bool(private) if(custom_data is not None): parameters['custom_data'] = custom_data return base.chatkit_request(chatkit_access_data, endpoint_parts, method="PUT", json_parameters=parameters)
def create_room(chatkit_access_data, name, private=True, user_ids=[], custom_data=None): endpoint_parts = ["rooms"] parameters = { "private": bool(private) } parameters['name'] = name if(user_ids not in [None, []]): parameters['user_ids'] = user_ids if(custom_data is not None): parameters['custom_data'] = custom_data return base.chatkit_request(chatkit_access_data, endpoint_parts, json_parameters=parameters, method="POST")
def send_message(chatkit_access_data, room_id, text, attachment_resource_link=None, attachment_type=None): """ attachment_resource_link:a valid url attachment_type: one of ['image', 'video', 'audio', 'file'] """ endpoint_parts = ["rooms", room_id, "messages"] parameters = {"text": text} if (attachment_type is not None and attachment_resource_link is not None): parameters['attachment'] = { 'resource_link': attachment_resource_link, 'type': attachment_type } return base.chatkit_request(chatkit_access_data, endpoint_parts, method="POST", json_parameters=parameters)
def delete_room(chatkit_access_data, room_id): endpoint_parts = ["rooms", room_id] return base.chatkit_request(chatkit_access_data, endpoint_parts, method="DELETE")
def fetch_room(chatkit_access_data, room_id): endpoint_parts = ['rooms', room_id] return base.chatkit_request(chatkit_access_data, endpoint_parts, method="GET")
def delete_message(chatkit_access_data, message_id): endpoint_parts = ["messages", message_id] return base.chatkit_request(chatkit_access_data, endpoint_parts, method="DELETE")