|
| 1 | +.. _conversations_api: |
| 2 | + |
| 3 | +============================================== |
| 4 | +Conversations API |
| 5 | +============================================== |
| 6 | +The Slack Conversations API provides your app with a unified interface to work with all the |
| 7 | +channel-like things encountered in Slack; public channels, private channels, direct messages, group |
| 8 | +direct messages, and our newest channel type, Shared Channels. |
| 9 | + |
| 10 | + |
| 11 | +See `Conversations API <https://api.slack.com/docs/conversations-api>`_ docs for more info. |
| 12 | + |
| 13 | +-------- |
| 14 | + |
| 15 | +Creating a direct message or multi-person direct message |
| 16 | +--------------------------------------------------------- |
| 17 | +This Conversations API method opens a multi-person direct message or just a 1:1 direct message. |
| 18 | + |
| 19 | +*Use conversations.create for public or private channels.* |
| 20 | + |
| 21 | +Provide 1 to 8 user IDs in the ``user`` parameter to open or resume a conversation. Providing only |
| 22 | +1 ID will create a direct message. Providing more will create an ``mpim``. |
| 23 | + |
| 24 | +If there are no conversations already in progress including that exact set of members, a new |
| 25 | +multi-person direct message conversation begins. |
| 26 | + |
| 27 | +Subsequent calls to ``conversations.open`` with the same set of users will return the already |
| 28 | +existing conversation. |
| 29 | + |
| 30 | + |
| 31 | +.. code-block:: python |
| 32 | +
|
| 33 | + from slackclient import SlackClient |
| 34 | +
|
| 35 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 36 | + sc = SlackClient(slack_token) |
| 37 | +
|
| 38 | + sc.api_call( |
| 39 | + "conversations.open", |
| 40 | + users=["W1234567890","U2345678901","U3456789012"] |
| 41 | + ) |
| 42 | +
|
| 43 | +See `conversations.open <https://api.slack.com/methods/conversations.open>`_ additional info. |
| 44 | + |
| 45 | +-------- |
| 46 | + |
| 47 | +Creating a public or private channel |
| 48 | +------------------------------------- |
| 49 | +Initiates a public or private channel-based conversation |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + from slackclient import SlackClient |
| 54 | +
|
| 55 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 56 | + sc = SlackClient(slack_token) |
| 57 | +
|
| 58 | + sc.api_call( |
| 59 | + "conversations.create", |
| 60 | + name="myprivatechannel", |
| 61 | + is_private=True |
| 62 | + ) |
| 63 | +
|
| 64 | +See `conversations.create <https://api.slack.com/methods/conversations.create>`_ additional info. |
| 65 | + |
| 66 | +-------- |
| 67 | + |
| 68 | +Getting information about a conversation |
| 69 | +----------------------------------------- |
| 70 | +This Conversations API method returns information about a workspace conversation. |
| 71 | + |
| 72 | +.. code-block:: python |
| 73 | +
|
| 74 | + from slackclient import SlackClient |
| 75 | +
|
| 76 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 77 | + sc = SlackClient(slack_token) |
| 78 | +
|
| 79 | + sc.api_call( |
| 80 | + "conversations.info", |
| 81 | + channel="C0XXXXXX", |
| 82 | + ) |
| 83 | +
|
| 84 | +See `conversations.info <https://api.slack.com/methods/conversations.info>`_ for more info. |
| 85 | + |
| 86 | + |
| 87 | +-------- |
| 88 | + |
| 89 | +Getting a list of conversations |
| 90 | +-------------------------------- |
| 91 | +This Conversations API method returns a list of all channel-like conversations in a workspace. |
| 92 | +The "channels" returned depend on what the calling token has access to and the directives placed |
| 93 | +in the ``types`` parameter. |
| 94 | + |
| 95 | + |
| 96 | +.. code-block:: python |
| 97 | +
|
| 98 | + from slackclient import SlackClient |
| 99 | +
|
| 100 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 101 | + sc = SlackClient(slack_token) |
| 102 | +
|
| 103 | + sc.api_call("conversations.list") |
| 104 | +
|
| 105 | +Only public conversations are included by default. You can include DMs and MPIMs by passing |
| 106 | +``public_channel,private_channel`` as the ``types`` in your request. |
| 107 | + |
| 108 | + |
| 109 | +.. code-block:: python |
| 110 | +
|
| 111 | + from slackclient import SlackClient |
| 112 | +
|
| 113 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 114 | + sc = SlackClient(slack_token) |
| 115 | +
|
| 116 | + sc.api_call( |
| 117 | + "conversations.list", |
| 118 | + types=["public_channel","private_channel"] |
| 119 | + ) |
| 120 | +
|
| 121 | +See `conversations.list <https://api.slack.com/methods/conversations.list>`_ for more info. |
| 122 | + |
| 123 | + |
| 124 | +-------- |
| 125 | + |
| 126 | +Leaving a conversation |
| 127 | +----------------------- |
| 128 | +Maybe you've finished up all the business you had in a conversation, or maybe you |
| 129 | +joined one by accident. This is how you leave a conversation. |
| 130 | + |
| 131 | +.. code-block:: python |
| 132 | +
|
| 133 | + from slackclient import SlackClient |
| 134 | +
|
| 135 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 136 | + sc = SlackClient(slack_token) |
| 137 | +
|
| 138 | + sc.api_call( |
| 139 | + "conversations.leave", |
| 140 | + channel="C0XXXXXXX" |
| 141 | + ) |
| 142 | +
|
| 143 | +See `conversations.leave <https://api.slack.com/methods/conversations.leave>`_ for more info. |
| 144 | + |
| 145 | +-------- |
| 146 | + |
| 147 | +Get conversation members |
| 148 | +------------------------------ |
| 149 | +Get a list fo the members of a conversation |
| 150 | + |
| 151 | +.. code-block:: python |
| 152 | +
|
| 153 | + from slackclient import SlackClient |
| 154 | +
|
| 155 | + slack_token = os.environ["SLACK_API_TOKEN"] |
| 156 | + sc = SlackClient(slack_token) |
| 157 | +
|
| 158 | + sc.api_call("conversations.members", |
| 159 | + channel="C0XXXXXXX" |
| 160 | + ) |
| 161 | +
|
| 162 | +See `users.list <https://api.slack.com/methods/conversations.members>`_ for more info. |
| 163 | + |
| 164 | +.. include:: metadata.rst |
0 commit comments