Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message reply and card support #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

philipsd6
Copy link
Contributor

With these changes, you can send a message to a room, get the message id from the response, and add a reply and attach a card, all nice and contained. For example:

my_room = hc.get_room('Test Room')
resp = my_room.message('Check this out @all!')
my_room.reply("You can add cards with HypChat!", resp['id'])
my_room.notification('This is a fallback message', card=my_fancy_card_dict, attach_to=resp['id'])

The card will slide right on top of the reply, attached to the first message!

Constructing my_fancy_card_dict is left as an exercise for the reader, but reading Sending Messages Using Cards should help.

@hanks
Copy link

hanks commented Dec 17, 2016

nice

@@ -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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants