Skip to content

Commit 373932c

Browse files
authored
Add options to send_message (#53)
1 parent f5adda3 commit 373932c

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

stream_chat/async_chat/channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55

66
class Channel(ChannelInterface):
7-
async def send_message(self, message, user_id):
7+
async def send_message(self, message, user_id, **options):
88
"""
99
Send a message to this channel
1010
1111
:param message: the Message object
1212
:param user_id: the ID of the user that created the message
1313
:return: the Server Response
1414
"""
15-
payload = {"message": add_user_id(message, user_id)}
15+
payload = {"message": add_user_id(message, user_id), **options}
1616
return await self.client.post(f"{self.url}/message", data=payload)
1717

1818
async def send_event(self, event, user_id):

stream_chat/base/channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def url(self):
1919
return f"channels/{self.channel_type}/{self.id}"
2020

2121
@abc.abstractmethod
22-
def send_message(self, message, user_id):
22+
def send_message(self, message, user_id, **options):
2323
"""
2424
Send a message to this channel
2525

stream_chat/channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55

66
class Channel(ChannelInterface):
7-
def send_message(self, message, user_id):
7+
def send_message(self, message, user_id, **options):
88
"""
99
Send a message to this channel
1010
1111
:param message: the Message object
1212
:param user_id: the ID of the user that created the message
1313
:return: the Server Response
1414
"""
15-
payload = {"message": add_user_id(message, user_id)}
15+
payload = {"message": add_user_id(message, user_id), **options}
1616
return self.client.post(f"{self.url}/message", data=payload)
1717

1818
def send_event(self, event, user_id):

stream_chat/tests/async_chat/test_channel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ async def test_create_without_id(self, event_loop, client, random_users):
2828
await channel.create(random_users[0]["id"])
2929
assert channel.id is not None
3030

31+
@pytest.mark.asyncio
32+
async def test_send_message_with_optinos(self, event_loop, channel, random_user):
33+
response = await channel.send_message(
34+
{"text": "hi"}, random_user["id"], skip_push=True
35+
)
36+
assert "message" in response
37+
assert response["message"]["text"] == "hi"
38+
3139
@pytest.mark.asyncio
3240
async def test_send_event(self, event_loop, channel, random_user):
3341
response = await channel.send_event({"type": "typing.start"}, random_user["id"])

stream_chat/tests/test_channel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def test_create_without_id(self, client, random_users):
2626
channel.create(random_users[0]["id"])
2727
assert channel.id is not None
2828

29+
def test_send_message_with_optinos(self, channel, random_user):
30+
response = channel.send_message(
31+
{"text": "hi"}, random_user["id"], skip_push=True
32+
)
33+
assert "message" in response
34+
assert response["message"]["text"] == "hi"
35+
2936
def test_send_event(self, channel, random_user):
3037
response = channel.send_event({"type": "typing.start"}, random_user["id"])
3138
assert "event" in response

0 commit comments

Comments
 (0)