Began block work

This commit is contained in:
Jacob Henry 2019-03-02 22:38:04 -05:00
parent bd42b27711
commit 7236ab8034
2 changed files with 45 additions and 2 deletions

20
main.py
View File

@ -56,6 +56,25 @@ def main() -> None:
event_handling = wrap.handle_events()
passive_handling = wrap.run_passives()
both = asyncio.gather(event_handling, passive_handling)
wrap.send_message("test", "#botzone", blocks=[
{
"type": "actions",
"block_id": "test_block_id",
"elements": [
{
"type": "button",
"action_id": "test_action_id",
"text": {
"type": "plain_text",
"text": "Send payload",
"emoji": False
}
}
]
}
])
event_loop.run_until_complete(both)
@ -90,6 +109,7 @@ async def help_callback(event: slack_util.Event, match: Match) -> None:
# Do not let my efforts fall to waste. Its a pitious legacy but its something, at least, to maybe tide the
# unending flow of work for poor Niko.
# run main
if __name__ == '__main__':
main()

View File

@ -283,7 +283,6 @@ class ClientWrapper(object):
# Handle each action separately
if "actions" in payload:
for action in payload["actions"]:
# Start building the event
ev = Event()
@ -405,7 +404,8 @@ class ClientWrapper(object):
else:
return self.send_message(text, event.conversation.conversation_id)
def send_message(self, text: str, channel_id: str, thread: str = None, broadcast: bool = False) -> dict:
def _send_core(self, api_method: str, text: str, channel_id: str, thread: str, broadcast: bool,
blocks: List[dict]) -> dict:
"""
Copy of the internal send message function of slack, with some helpful options.
Returns the JSON response.
@ -415,9 +415,32 @@ class ClientWrapper(object):
kwargs["thread_ts"] = thread
if broadcast:
kwargs["reply_broadcast"] = True
if blocks:
kwargs["blocks"] = blocks
return self.api_call("chat.postMessage", **kwargs)
def send_message(self,
text: str,
channel_id: str,
thread: str = None,
broadcast: bool = False,
blocks: List[dict] = None) -> dict:
"""
Wraps _send_core for normal messages
"""
return self._send_core("chat.postMessage", text, channel_id, thread, broadcast, blocks)
def send_ephemeral(self,
text: str,
channel_id: str,
thread: str = None,
blocks: List[dict] = None) -> dict:
"""
Wraps _send_core for ephemeral messages
"""
return self._send_core("chat.postEphemeral", text, channel_id, thread, False, blocks)
# Update slack data
def update_channels(self):