Skip to content

Commit

Permalink
Adapt botogram to the recent API changes.
Browse files Browse the repository at this point in the history
The GroupChat object was removed, and a generic Chat object was introduced
instead of the old one. This object is used for private conversations, group
chats and channels, so the Message.chat attribute won't contain anymore the
User or the GroupChat object, but only the Chat one.

Also the API change introduced support for managing channels. Details of the
implementation are tracked on issue #7.
  • Loading branch information
Pietro Albini committed Oct 9, 2015
1 parent d4f3bdd commit 850d6e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions botogram/frozenbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def command(self, name):
def send(self, chat, message, preview=True, reply_to=None, syntax=None,
extra=None):
"""Send a message in a chat"""
obj = objects.GenericChat({"id": chat}, self.api)
obj = objects.Chat({"id": chat, type: ""}, self.api)
obj.send(message, preview, reply_to, syntax, extra)

def send_photo(self, chat, path, caption="", reply_to=None, extra=None):
"""Send a photo in a chat"""
obj = objects.GenericChat({"id": chat}, self.api)
obj = objects.GenericChat({"id": chat, type: ""}, self.api)

This comment has been minimized.

Copy link
@tsculpt

tsculpt Oct 17, 2015

Contributor

Looks like a reference to objects.GenericChat was missed in send_photo.
Cheers, Brad

This comment has been minimized.

Copy link
@pietroalbini

pietroalbini Oct 17, 2015

Contributor

Woops, later I'll fix this

This comment has been minimized.

Copy link
@pietroalbini

pietroalbini Oct 17, 2015

Contributor

And it's fixed.
Thanks @tsculpt :-)

obj.send_photo(path, caption, reply_to, extra)

# Let's process the messages
Expand Down
22 changes: 10 additions & 12 deletions botogram/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class EmptyObject(BaseObject):
pass


class GenericChat(BaseObject, mixins.ChatMixin):
"""Internal representation of a generic chat"""

required = {
"id": int,
}


class User(BaseObject, mixins.ChatMixin):
"""Telegram API representation of an user
Expand All @@ -39,15 +31,21 @@ class User(BaseObject, mixins.ChatMixin):
}


class GroupChat(BaseObject, mixins.ChatMixin):
"""Telegram API representation of a group chat
class Chat(BaseObject, mixins.ChatMixin):
"""Telegram API representation of a chat
https://core.telegram.org/bots/api#groupchat
https://core.telegram.org/bots/api#chat
"""

required = {
"id": int,
"type": str,
}
optional = {
"title": str,
"username": str,
"first_name": str,
"last_name": str,
}


Expand Down Expand Up @@ -204,7 +202,7 @@ class Message(BaseObject, mixins.MessageMixin):
"message_id": int,
"from": User,
"date": int,
"chat": one_of(User, GroupChat),
"chat": Chat,
}
optional = {
"forward_from": User,
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def sample_update(request):
"message_id": 2,
"chat": {
"id": -1,
"type": "group",
"title": "test",
},
"from": {
Expand Down

0 comments on commit 850d6e9

Please sign in to comment.