|
| 1 | +--- |
| 2 | +layout: doc |
| 3 | +--- |
| 4 | + |
| 5 | +<script setup lang="ts"> |
| 6 | +import { ref, computed } from 'vue'; |
| 7 | +import VPLink from 'vitepress/dist/client/theme-default/components/VPLink.vue'; |
| 8 | +import { |
| 9 | + appRedirect, |
| 10 | + channelRedirect, |
| 11 | + open, |
| 12 | + openApp, |
| 13 | + openChannel, |
| 14 | + openFile, |
| 15 | + openUser, |
| 16 | + shareFile, |
| 17 | +} from 'protocol-launcher/slack'; |
| 18 | +import { SelectInstallationMethod } from '../../.vitepress/components'; |
| 19 | +import { |
| 20 | + appRedirectParams, |
| 21 | + channelRedirectParams, |
| 22 | + openAppParams, |
| 23 | + openChannelParams, |
| 24 | + openFileParams, |
| 25 | + openParams, |
| 26 | + openUserParams, |
| 27 | + shareFileParams, |
| 28 | +} from '../../.vitepress/constants/slack'; |
| 29 | + |
| 30 | +const currentMethod = ref('On-Demand'); |
| 31 | +const importPath = computed(() => currentMethod.value === 'On-Demand' ? 'protocol-launcher/slack' : 'protocol-launcher'); |
| 32 | +</script> |
| 33 | + |
| 34 | +# Slack |
| 35 | + |
| 36 | +[Slack](https://slack.com/) is a collaboration platform for team communication, channels, messages, files, and apps. **Protocol Launcher** allows you to generate deep links to open Slack workspaces, channels, users, apps, and files. |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +There are two ways to use this library: |
| 41 | + |
| 42 | +- On-Demand import from subpaths enables tree-shaking and keeps bundles small. |
| 43 | +- Full Import from the root package is convenient but includes all app modules. |
| 44 | + |
| 45 | +Pick On-Demand for production builds; Full Import is fine for quick scripts or demos. |
| 46 | + |
| 47 | +<SelectInstallationMethod v-model="currentMethod" /> |
| 48 | + |
| 49 | +## Notes |
| 50 | + |
| 51 | +Slack's `slack://` URI templates use Slack IDs for workspaces, channels, users, apps, and files. They do not support workspace subdomains, channel names, user names, or filenames. Use Slack's `app_redirect` URL when you need the official channel-name redirect form. |
| 52 | + |
| 53 | +### Open Slack |
| 54 | + |
| 55 | +Open the native Slack client. Passing `team` switches to a specific workspace. |
| 56 | + |
| 57 | +```ts-vue [{{currentMethod}}] |
| 58 | +import { {{ currentMethod === 'On-Demand' ? 'open' : 'slack' }} } from '{{ importPath }}' |
| 59 | +
|
| 60 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}open({ |
| 61 | + team: '{{ openParams.team }}', |
| 62 | +}) |
| 63 | +``` |
| 64 | + |
| 65 | +<div class="flex justify-center"> |
| 66 | + <VPLink :href="open(openParams)" target="_self"> |
| 67 | + Open Slack |
| 68 | + </VPLink> |
| 69 | +</div> |
| 70 | + |
| 71 | +### App Redirect |
| 72 | + |
| 73 | +Create a Slack `app_redirect` URL that opens a direct message with an app or bot. |
| 74 | + |
| 75 | +```ts-vue [{{currentMethod}}] |
| 76 | +import { {{ currentMethod === 'On-Demand' ? 'appRedirect' : 'slack' }} } from '{{ importPath }}' |
| 77 | +
|
| 78 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}appRedirect({ |
| 79 | + app: '{{ appRedirectParams.app }}', |
| 80 | + team: '{{ appRedirectParams.team }}', |
| 81 | +}) |
| 82 | +``` |
| 83 | + |
| 84 | +<div class="flex justify-center"> |
| 85 | + <VPLink :href="appRedirect(appRedirectParams)" target="_self"> |
| 86 | + Open Slack App Redirect |
| 87 | + </VPLink> |
| 88 | +</div> |
| 89 | + |
| 90 | +### Channel Redirect |
| 91 | + |
| 92 | +Create a Slack `app_redirect` URL that opens a channel by ID or by name. |
| 93 | + |
| 94 | +```ts-vue [{{currentMethod}}] |
| 95 | +import { {{ currentMethod === 'On-Demand' ? 'channelRedirect' : 'slack' }} } from '{{ importPath }}' |
| 96 | +
|
| 97 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}channelRedirect({ |
| 98 | + channel: '{{ channelRedirectParams.channel }}', |
| 99 | + team: '{{ channelRedirectParams.team }}', |
| 100 | +}) |
| 101 | +``` |
| 102 | + |
| 103 | +<div class="flex justify-center"> |
| 104 | + <VPLink :href="channelRedirect(channelRedirectParams)" target="_self"> |
| 105 | + Open Slack Channel Redirect |
| 106 | + </VPLink> |
| 107 | +</div> |
| 108 | + |
| 109 | +### Open App Home |
| 110 | + |
| 111 | +Open a Slack App Home by workspace ID and app ID. The optional `tab` value can be `home`, `about`, or `messages`. |
| 112 | + |
| 113 | +```ts-vue [{{currentMethod}}] |
| 114 | +import { {{ currentMethod === 'On-Demand' ? 'openApp' : 'slack' }} } from '{{ importPath }}' |
| 115 | +
|
| 116 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}openApp({ |
| 117 | + team: '{{ openAppParams.team }}', |
| 118 | + id: '{{ openAppParams.id }}', |
| 119 | + tab: '{{ openAppParams.tab }}', |
| 120 | +}) |
| 121 | +``` |
| 122 | + |
| 123 | +<div class="flex justify-center"> |
| 124 | + <VPLink :href="openApp(openAppParams)" target="_self"> |
| 125 | + Open Slack App Home |
| 126 | + </VPLink> |
| 127 | +</div> |
| 128 | + |
| 129 | +### Open Channel |
| 130 | + |
| 131 | +Open a Slack channel by workspace ID and channel ID. |
| 132 | + |
| 133 | +```ts-vue [{{currentMethod}}] |
| 134 | +import { {{ currentMethod === 'On-Demand' ? 'openChannel' : 'slack' }} } from '{{ importPath }}' |
| 135 | +
|
| 136 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}openChannel({ |
| 137 | + team: '{{ openChannelParams.team }}', |
| 138 | + id: '{{ openChannelParams.id }}', |
| 139 | +}) |
| 140 | +``` |
| 141 | + |
| 142 | +<div class="flex justify-center"> |
| 143 | + <VPLink :href="openChannel(openChannelParams)" target="_self"> |
| 144 | + Open Slack Channel |
| 145 | + </VPLink> |
| 146 | +</div> |
| 147 | + |
| 148 | +### Open Direct Message |
| 149 | + |
| 150 | +Open a direct message with a Slack user by workspace ID and user ID. |
| 151 | + |
| 152 | +```ts-vue [{{currentMethod}}] |
| 153 | +import { {{ currentMethod === 'On-Demand' ? 'openUser' : 'slack' }} } from '{{ importPath }}' |
| 154 | +
|
| 155 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}openUser({ |
| 156 | + team: '{{ openUserParams.team }}', |
| 157 | + id: '{{ openUserParams.id }}', |
| 158 | +}) |
| 159 | +``` |
| 160 | + |
| 161 | +<div class="flex justify-center"> |
| 162 | + <VPLink :href="openUser(openUserParams)" target="_self"> |
| 163 | + Open Slack Direct Message |
| 164 | + </VPLink> |
| 165 | +</div> |
| 166 | + |
| 167 | +### Open File |
| 168 | + |
| 169 | +Open a Slack file by workspace ID and file ID. |
| 170 | + |
| 171 | +```ts-vue [{{currentMethod}}] |
| 172 | +import { {{ currentMethod === 'On-Demand' ? 'openFile' : 'slack' }} } from '{{ importPath }}' |
| 173 | +
|
| 174 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}openFile({ |
| 175 | + team: '{{ openFileParams.team }}', |
| 176 | + id: '{{ openFileParams.id }}', |
| 177 | +}) |
| 178 | +``` |
| 179 | + |
| 180 | +<div class="flex justify-center"> |
| 181 | + <VPLink :href="openFile(openFileParams)" target="_self"> |
| 182 | + Open Slack File |
| 183 | + </VPLink> |
| 184 | +</div> |
| 185 | + |
| 186 | +### Share File |
| 187 | + |
| 188 | +Open Slack's file sharing dialog by workspace ID and file ID. |
| 189 | + |
| 190 | +```ts-vue [{{currentMethod}}] |
| 191 | +import { {{ currentMethod === 'On-Demand' ? 'shareFile' : 'slack' }} } from '{{ importPath }}' |
| 192 | +
|
| 193 | +const url = {{currentMethod === 'On-Demand' ? '' : 'slack.'}}shareFile({ |
| 194 | + team: '{{ shareFileParams.team }}', |
| 195 | + id: '{{ shareFileParams.id }}', |
| 196 | +}) |
| 197 | +``` |
| 198 | + |
| 199 | +<div class="flex justify-center"> |
| 200 | + <VPLink :href="shareFile(shareFileParams)" target="_self"> |
| 201 | + Share Slack File |
| 202 | + </VPLink> |
| 203 | +</div> |
| 204 | + |
| 205 | +## Official Documentation |
| 206 | + |
| 207 | +- [Slack Deep Linking](https://docs.slack.dev/interactivity/deep-linking/) |
0 commit comments