Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Add dialog open method from https://github.com/prestonhale/slacker/ fixed by jahirfiquitiva #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
23 changes: 18 additions & 5 deletions slacker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from slacker.utils import get_item_id_by_name


Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove this line as well?

__version__ = '0.9.65'

API_BASE_URL = 'https://slack.com/api/{api}'
Expand All @@ -34,7 +33,7 @@
'Stars', 'Emoji', 'Presence', 'RTM', 'Team', 'Reactions', 'Pins',
'UserGroups', 'UserGroupsUsers', 'MPIM', 'OAuth', 'DND', 'Bots',
'FilesComments', 'Reminders', 'TeamProfile', 'UsersProfile',
'IDPGroups', 'Apps', 'AppsPermissions', 'Slacker']
'IDPGroups', 'Apps', 'AppsPermissions', 'Slacker', 'Dialog']


class Error(Exception):
Expand All @@ -47,6 +46,7 @@ def __init__(self, body):
self.body = json.loads(body)
self.successful = self.body['ok']
self.error = self.body.get('error')
self.message = self.body.get('response_metadata', {}).get('messages')
Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove this line as it's not a part of this PR? There's another PR addressing this.


def __str__(self):
return json.dumps(self.body)
Expand Down Expand Up @@ -78,7 +78,7 @@ def _request(self, method, api, **kwargs):

# handle HTTP 429 as documented at
# https://api.slack.com/docs/rate-limits
elif response.status_code == requests.codes.too_many: # HTTP 429
elif response.status_code == requests.codes.too_many: # HTTP 429
time.sleep(int(response.headers.get('retry-after', DEFAULT_WAIT)))
continue

Expand All @@ -96,7 +96,10 @@ def _request(self, method, api, **kwargs):

response = Response(response.text)
if not response.successful:
raise Error(response.error)
error = response.error
if response.message:
error = "{error}: {response.message}"
raise Error(error)
Comment on lines -99 to +102
Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove this section as it's not directly related to this PR? Although I'm not a big fan of this as I want to keep the implementation as close as the original API as possible.


return response

Expand Down Expand Up @@ -456,7 +459,7 @@ def history(self, channel, latest=None, oldest=None, count=None,
'oldest': oldest,
'count': count,
'inclusive': inclusive,
'unreads' : int(unreads)
'unreads': int(unreads)
Comment on lines -459 to +462
Copy link
Owner

Choose a reason for hiding this comment

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

Nice 🍰 Thanks.

})

def replies(self, channel, thread_ts):
Expand Down Expand Up @@ -988,6 +991,15 @@ def permissions(self):
return self._permissions


class Dialog(BaseAPI):
def open(self, dialog, trigger_id):
return self.post('dialog.open',
data={
'dialog': json.dumps(dialog),
'trigger_id': trigger_id
})


class IncomingWebhook(object):
def __init__(self, url=None, timeout=DEFAULT_TIMEOUT, proxies=None):
self.url = url
Expand Down Expand Up @@ -1044,6 +1056,7 @@ def __init__(self, token, incoming_webhook_url=None,
self.reactions = Reactions(**api_args)
self.idpgroups = IDPGroups(**api_args)
self.usergroups = UserGroups(**api_args)
self.dialog = Dialog(**api_args)
self.incomingwebhook = IncomingWebhook(url=incoming_webhook_url,
timeout=timeout, proxies=proxies)

Expand Down