Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions hypchat/restobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ def message(self, message):
Allows a user to send a message to a room.
"""
data = {'message': message}
self._requests.post(self.url + '/message', data=data)
resp = self._requests.post(self.url + '/message', data=data)
return Linker._obj_from_text(resp.text, self._requests)

def notification(self, message, color=None, notify=False, format=None):
def notification(self, message, card=None, color=None, notify=False, format=None, attach_to=None):
"""
Send a message to a room.
"""
Expand All @@ -156,7 +157,7 @@ def notification(self, message, color=None, notify=False, format=None):
format = 'text'
else:
format = 'html'
data = {'message': message, 'notify': notify, 'message_format': format}
data = {'message': message, 'card': card, 'notify': notify, 'message_format': format, 'attach_to': attach_to}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this code, and if attach_to is None, there will be error like below:

hypchat.requests.HttpBadRequest: {
  "error": {
    "code": 400,
    "description": "Value {value!r} is not of type {expected_type!r}",
    "expected_type": "string",
    "field": "attach_to",
    "message": "Value None for field 'attach_to' is not of type 'string'",
    "type": "Bad Request",
    "validation": "type",
    "value": null
  }

Seems to use None check will be better:

if card:
    data['card'] = card
if attach_to:
    data['attach_to'] = attach_to

if color:
data['color'] = color
self._requests.post(self.url + '/notification', data=data)
Expand Down