Skip to content

Commit c1872ed

Browse files
authored
Merge branch 'main' into docs-haley-order-confirmation-tutorial
2 parents af2066b + c8a50be commit c1872ed

File tree

12 files changed

+130
-3
lines changed

12 files changed

+130
-3
lines changed

docs/english/building-an-app.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ Now that you have a basic app up and running, you can start exploring how to mak
475475

476476
* Read through the concepts pages to learn about the different methods and features your Bolt app has access to.
477477

478-
* Explore the different events your bot can listen to with the [`app.event()`](/tools/bolt-python/concepts/event-listening) method. All of the events are listed [on the API docs site](/reference/events).
478+
* Explore the different events your bot can listen to with the [`app.event()`](/tools/bolt-python/concepts/event-listening) method. View the full events reference docs [here](/reference/events).
479479

480-
* Bolt allows you to [call Web API methods](/tools/bolt-python/concepts/web-api) with the client attached to your app. There are [over 200 methods](/reference/methods) on our API site.
480+
* Bolt allows you to [call Web API methods](/tools/bolt-python/concepts/web-api) with the client attached to your app. There are over 200 methods; view them [here](/reference/methods).
481481

482-
* Learn more about the different token types [on the API docs site](/authentication/tokens). Your app may need different tokens depending on the actions you want it to perform.
482+
* Learn more about the different token types in the [tokens guide](/authentication/tokens). Your app may need different tokens depending on the actions you want it to perform.

docs/english/getting-started.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,41 @@ This will open the following page:
279279

280280
On these pages you're free to make changes such as updating your app icon, configuring app features, and perhaps even distributing your app!
281281

282+
## Adding AI features {#ai-features}
283+
284+
Now that you're familiar with a basic app setup, try it out again, this time using the AI agent template!
285+
286+
<Tabs groupId="cli-or-terminal">
287+
<TabItem value="cli" label="Slack CLI">
288+
289+
Get started with the agent template:
290+
291+
```sh
292+
$ slack create ai-app --template slack-samples/bolt-python-assistant-template
293+
$ cd ai-app
294+
```
295+
296+
</TabItem>
297+
<TabItem value="terminal" label="Terminal">
298+
299+
Get started with the agent template:
300+
301+
```sh
302+
$ git clone https://github.com/slack-samples/bolt-python-assistant-template ai-app
303+
$ cd ai-app
304+
```
305+
306+
Using this method, be sure to set the app and bot tokens as we did in the [Running the app](#running-the-app) section above.
307+
308+
</TabItem>
309+
</Tabs>
310+
311+
Once the project is created, update the `.env.sample` file by setting the `OPENAI_API_KEY` with the value of your key and removing the `.sample` from the file name.
312+
313+
In the `ai` folder of this app, you'll find default instructions for the LLM and an OpenAI client setup.
314+
315+
The `listeners` include utilities intended for messaging with an LLM. Those are outlined in detail in the guide to [Using AI in apps](/tools/bolt-python/concepts/ai-apps) and [Sending messages](/tools/bolt-python/concepts/message-sending).
316+
282317
## Next steps {#next-steps}
283318

284319
Congrats once more on getting up and running with this quick start.

slack_bolt/context/complete/async_complete.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class AsyncComplete:
88
client: AsyncWebClient
99
function_execution_id: Optional[str]
10+
_called: bool
1011

1112
def __init__(
1213
self,
@@ -15,6 +16,7 @@ def __init__(
1516
):
1617
self.client = client
1718
self.function_execution_id = function_execution_id
19+
self._called = False
1820

1921
async def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> AsyncSlackResponse:
2022
"""Signal the successful completion of the custom function.
@@ -31,6 +33,15 @@ async def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> AsyncSlack
3133
if self.function_execution_id is None:
3234
raise ValueError("complete is unsupported here as there is no function_execution_id")
3335

36+
self._called = True
3437
return await self.client.functions_completeSuccess(
3538
function_execution_id=self.function_execution_id, outputs=outputs or {}
3639
)
40+
41+
def has_been_called(self) -> bool:
42+
"""Check if this complete function has been called.
43+
44+
Returns:
45+
bool: True if the complete function has been called, False otherwise.
46+
"""
47+
return self._called

slack_bolt/context/complete/complete.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Complete:
88
client: WebClient
99
function_execution_id: Optional[str]
10+
_called: bool
1011

1112
def __init__(
1213
self,
@@ -15,6 +16,7 @@ def __init__(
1516
):
1617
self.client = client
1718
self.function_execution_id = function_execution_id
19+
self._called = False
1820

1921
def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> SlackResponse:
2022
"""Signal the successful completion of the custom function.
@@ -31,4 +33,13 @@ def __call__(self, outputs: Optional[Dict[str, Any]] = None) -> SlackResponse:
3133
if self.function_execution_id is None:
3234
raise ValueError("complete is unsupported here as there is no function_execution_id")
3335

36+
self._called = True
3437
return self.client.functions_completeSuccess(function_execution_id=self.function_execution_id, outputs=outputs or {})
38+
39+
def has_been_called(self) -> bool:
40+
"""Check if this complete function has been called.
41+
42+
Returns:
43+
bool: True if the complete function has been called, False otherwise.
44+
"""
45+
return self._called

slack_bolt/context/fail/async_fail.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class AsyncFail:
88
client: AsyncWebClient
99
function_execution_id: Optional[str]
10+
_called: bool
1011

1112
def __init__(
1213
self,
@@ -15,6 +16,7 @@ def __init__(
1516
):
1617
self.client = client
1718
self.function_execution_id = function_execution_id
19+
self._called = False
1820

1921
async def __call__(self, error: str) -> AsyncSlackResponse:
2022
"""Signal that the custom function failed to complete.
@@ -31,4 +33,13 @@ async def __call__(self, error: str) -> AsyncSlackResponse:
3133
if self.function_execution_id is None:
3234
raise ValueError("fail is unsupported here as there is no function_execution_id")
3335

36+
self._called = True
3437
return await self.client.functions_completeError(function_execution_id=self.function_execution_id, error=error)
38+
39+
def has_been_called(self) -> bool:
40+
"""Check if this fail function has been called.
41+
42+
Returns:
43+
bool: True if the fail function has been called, False otherwise.
44+
"""
45+
return self._called

slack_bolt/context/fail/fail.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class Fail:
88
client: WebClient
99
function_execution_id: Optional[str]
10+
_called: bool
1011

1112
def __init__(
1213
self,
@@ -15,6 +16,7 @@ def __init__(
1516
):
1617
self.client = client
1718
self.function_execution_id = function_execution_id
19+
self._called = False
1820

1921
def __call__(self, error: str) -> SlackResponse:
2022
"""Signal that the custom function failed to complete.
@@ -31,4 +33,13 @@ def __call__(self, error: str) -> SlackResponse:
3133
if self.function_execution_id is None:
3234
raise ValueError("fail is unsupported here as there is no function_execution_id")
3335

36+
self._called = True
3437
return self.client.functions_completeError(function_execution_id=self.function_execution_id, error=error)
38+
39+
def has_been_called(self) -> bool:
40+
"""Check if this fail function has been called.
41+
42+
Returns:
43+
bool: True if the fail function has been called, False otherwise.
44+
"""
45+
return self._called

tests/scenario_tests/test_function.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,20 @@ def reverse(body, event, context, client, complete, inputs):
300300
assert context.client.token == "xwfp-valid"
301301
assert client.token == "xwfp-valid"
302302
assert complete.client.token == "xwfp-valid"
303+
assert complete.has_been_called() is False
303304
complete(
304305
outputs={"reverseString": "olleh"},
305306
)
307+
assert complete.has_been_called() is True
306308

307309

308310
def reverse_error(body, event, fail):
309311
assert body == function_body
310312
assert event == function_body["event"]
311313
assert fail.function_execution_id == "Fx111"
314+
assert fail.has_been_called() is False
312315
fail(error="there was an error")
316+
assert fail.has_been_called() is True
313317

314318

315319
def complete_it(body, event, complete):

tests/scenario_tests_async/test_function.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,22 @@ async def reverse(body, event, client, context, complete, inputs):
312312
assert context.client.token == "xwfp-valid"
313313
assert client.token == "xwfp-valid"
314314
assert complete.client.token == "xwfp-valid"
315+
assert complete.has_been_called() is False
315316
await complete(
316317
outputs={"reverseString": "olleh"},
317318
)
319+
assert complete.has_been_called() is True
318320

319321

320322
async def reverse_error(body, event, fail):
321323
assert body == function_body
322324
assert event == function_body["event"]
323325
assert fail.function_execution_id == "Fx111"
326+
assert fail.has_been_called() is False
324327
await fail(
325328
error="there was an error",
326329
)
330+
assert fail.has_been_called() is True
327331

328332

329333
async def complete_it(body, event, complete):

tests/slack_bolt/context/test_complete.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ def test_complete_no_function_execution_id(self):
3030

3131
with pytest.raises(ValueError):
3232
complete(outputs={"key": "value"})
33+
34+
def test_has_been_called_false_initially(self):
35+
complete = Complete(client=self.web_client, function_execution_id="fn1111")
36+
assert complete.has_been_called() is False
37+
38+
def test_has_been_called_true_after_complete(self):
39+
complete = Complete(client=self.web_client, function_execution_id="fn1111")
40+
complete(outputs={"key": "value"})
41+
assert complete.has_been_called() is True

tests/slack_bolt/context/test_fail.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ def test_fail_no_function_execution_id(self):
3030

3131
with pytest.raises(ValueError):
3232
fail(error="there was an error")
33+
34+
def test_has_been_called_false_initially(self):
35+
fail = Fail(client=self.web_client, function_execution_id="fn1111")
36+
assert fail.has_been_called() is False
37+
38+
def test_has_been_called_true_after_fail(self):
39+
fail = Fail(client=self.web_client, function_execution_id="fn1111")
40+
fail(error="there was an error")
41+
assert fail.has_been_called() is True

0 commit comments

Comments
 (0)