Skip to content

Commit 143e8e3

Browse files
make things work for org apps
1 parent 9aaedf7 commit 143e8e3

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

slack_bolt/middleware/attaching_agent_kwargs/async_attaching_agent_kwargs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def async_process(
4444
req.context["say_stream"] = AsyncSayStream(
4545
client=req.context.client,
4646
channel=req.context.channel_id,
47-
recipient_team_id=req.context.team_id,
47+
recipient_team_id=req.context.team_id or req.context.enterprise_id,
4848
recipient_user_id=req.context.user_id,
4949
thread_ts=thread_ts,
5050
)

slack_bolt/middleware/attaching_agent_kwargs/attaching_agent_kwargs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def process(self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], Bo
3838
req.context["say_stream"] = SayStream(
3939
client=req.context.client,
4040
channel=req.context.channel_id,
41-
recipient_team_id=req.context.team_id,
41+
recipient_team_id=req.context.team_id or req.context.enterprise_id,
4242
recipient_user_id=req.context.user_id,
4343
thread_ts=thread_ts,
4444
)

tests/scenario_tests/test_events_say_stream.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ def handle_mention(say_stream: SayStream, context: BoltContext):
6464
assert response.status == 200
6565
assert_target_called(called)
6666

67+
def test_say_stream_with_org_level_install(self):
68+
app = App(client=self.web_client)
69+
called = {"value": False}
70+
71+
@app.event("app_mention")
72+
def handle_mention(say_stream: SayStream, context: BoltContext):
73+
assert context.team_id is None
74+
assert context.enterprise_id == "E111"
75+
assert say_stream is not None
76+
assert isinstance(say_stream, SayStream)
77+
assert say_stream.recipient_team_id == "E111"
78+
called["value"] = True
79+
80+
request = BoltRequest(body=org_app_mention_event_body, mode="socket_mode")
81+
response = app.dispatch(request)
82+
assert response.status == 200
83+
assert_target_called(called)
84+
6785
def test_say_stream_injected_for_threaded_message(self):
6886
app = App(client=self.web_client)
6987
called = {"value": False}
@@ -187,3 +205,34 @@ def handle_view(ack, say_stream, context: BoltContext):
187205
response = app.dispatch(request)
188206
assert response.status == 200
189207
assert_target_called(called)
208+
209+
210+
org_app_mention_event_body = {
211+
"token": "verification_token",
212+
"team_id": "T111",
213+
"enterprise_id": "E111",
214+
"api_app_id": "A111",
215+
"event": {
216+
"client_msg_id": "9cbd4c5b-7ddf-4ede-b479-ad21fca66d63",
217+
"type": "app_mention",
218+
"text": "<@W111> Hi there!",
219+
"user": "W222",
220+
"ts": "1595926230.009600",
221+
"team": "T111",
222+
"channel": "C111",
223+
"event_ts": "1595926230.009600",
224+
},
225+
"type": "event_callback",
226+
"event_id": "Ev111",
227+
"event_time": 1595926230,
228+
"authorizations": [
229+
{
230+
"enterprise_id": "E111",
231+
"team_id": None,
232+
"user_id": "W111",
233+
"is_bot": True,
234+
"is_enterprise_install": True,
235+
}
236+
],
237+
"is_ext_shared_channel": False,
238+
}

tests/scenario_tests_async/test_events_say_stream.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ async def handle_mention(say_stream: AsyncSayStream, context: AsyncBoltContext):
6969
assert response.status == 200
7070
await assert_target_called(called)
7171

72+
@pytest.mark.asyncio
73+
async def test_say_stream_with_org_level_install(self):
74+
app = AsyncApp(client=self.web_client)
75+
called = {"value": False}
76+
77+
@app.event("app_mention")
78+
async def handle_mention(say_stream: AsyncSayStream, context: AsyncBoltContext):
79+
assert context.team_id is None
80+
assert context.enterprise_id == "E111"
81+
assert say_stream is not None
82+
assert isinstance(say_stream, AsyncSayStream)
83+
assert say_stream.recipient_team_id == "E111"
84+
called["value"] = True
85+
86+
request = AsyncBoltRequest(body=org_app_mention_event_body, mode="socket_mode")
87+
response = await app.async_dispatch(request)
88+
assert response.status == 200
89+
await assert_target_called(called)
90+
7291
@pytest.mark.asyncio
7392
async def test_say_stream_injected_for_threaded_message(self):
7493
app = AsyncApp(client=self.web_client)
@@ -198,3 +217,34 @@ async def handle_view(ack, say_stream, context: AsyncBoltContext):
198217
response = await app.async_dispatch(request)
199218
assert response.status == 200
200219
await assert_target_called(called)
220+
221+
222+
org_app_mention_event_body = {
223+
"token": "verification_token",
224+
"team_id": "T111",
225+
"enterprise_id": "E111",
226+
"api_app_id": "A111",
227+
"event": {
228+
"client_msg_id": "9cbd4c5b-7ddf-4ede-b479-ad21fca66d63",
229+
"type": "app_mention",
230+
"text": "<@W111> Hi there!",
231+
"user": "W222",
232+
"ts": "1595926230.009600",
233+
"team": "T111",
234+
"channel": "C111",
235+
"event_ts": "1595926230.009600",
236+
},
237+
"type": "event_callback",
238+
"event_id": "Ev111",
239+
"event_time": 1595926230,
240+
"authorizations": [
241+
{
242+
"enterprise_id": "E111",
243+
"team_id": None,
244+
"user_id": "W111",
245+
"is_bot": True,
246+
"is_enterprise_install": True,
247+
}
248+
],
249+
"is_ext_shared_channel": False,
250+
}

0 commit comments

Comments
 (0)