@@ -139,6 +139,182 @@ async def test_stable_auto_ack(self):
139139 response = await app .async_dispatch (request )
140140 assert response .status == 200
141141
142+ @pytest .mark .asyncio
143+ async def test_self_events (self ):
144+ app = AsyncApp (client = self .web_client , signing_secret = self .signing_secret ,)
145+ app .event ("reaction_added" )(whats_up )
146+
147+ self_event = {
148+ "token" : "verification_token" ,
149+ "team_id" : "T111" ,
150+ "enterprise_id" : "E111" ,
151+ "api_app_id" : "A111" ,
152+ "event" : {
153+ "type" : "reaction_added" ,
154+ "user" : "W23456789" , # bot_user_id
155+ "item" : {
156+ "type" : "message" ,
157+ "channel" : "C111" ,
158+ "ts" : "1599529504.000400" ,
159+ },
160+ "reaction" : "heart_eyes" ,
161+ "item_user" : "W111" ,
162+ "event_ts" : "1599616881.000800" ,
163+ },
164+ "type" : "event_callback" ,
165+ "event_id" : "Ev111" ,
166+ "event_time" : 1599616881 ,
167+ "authed_users" : ["W111" ],
168+ }
169+ timestamp , body = str (int (time ())), json .dumps (self_event )
170+ request = AsyncBoltRequest (
171+ body = body , headers = self .build_headers (timestamp , body )
172+ )
173+ response = await app .async_dispatch (request )
174+ assert response .status == 200
175+ assert self .mock_received_requests ["/auth.test" ] == 1
176+ await asyncio .sleep (1 ) # wait a bit after auto ack()
177+ # The listener should not be executed
178+ assert self .mock_received_requests .get ("/chat.postMessage" ) is None
179+
180+ @pytest .mark .asyncio
181+ async def test_self_joined_left_events (self ):
182+ app = AsyncApp (client = self .web_client , signing_secret = self .signing_secret ,)
183+ app .event ("reaction_added" )(whats_up )
184+
185+ join_event_body = {
186+ "token" : "verification_token" ,
187+ "team_id" : "T111" ,
188+ "enterprise_id" : "E111" ,
189+ "api_app_id" : "A111" ,
190+ "event" : {
191+ "type" : "member_joined_channel" ,
192+ "user" : "W23456789" , # bot_user_id
193+ "channel" : "C111" ,
194+ "channel_type" : "C" ,
195+ "team" : "T111" ,
196+ "inviter" : "U222" ,
197+ },
198+ "type" : "event_callback" ,
199+ "event_id" : "Ev111" ,
200+ "event_time" : 1599616881 ,
201+ "authed_users" : ["W111" ],
202+ }
203+
204+ left_event_body = {
205+ "token" : "verification_token" ,
206+ "team_id" : "T111" ,
207+ "enterprise_id" : "E111" ,
208+ "api_app_id" : "A111" ,
209+ "event" : {
210+ "type" : "member_left_channel" ,
211+ "user" : "W23456789" , # bot_user_id
212+ "channel" : "C111" ,
213+ "channel_type" : "C" ,
214+ "team" : "T111" ,
215+ },
216+ "type" : "event_callback" ,
217+ "event_id" : "Ev111" ,
218+ "event_time" : 1599616881 ,
219+ "authed_users" : ["W111" ],
220+ }
221+
222+ @app .event ("member_joined_channel" )
223+ async def handle_member_joined_channel (say ):
224+ await say ("What's up?" )
225+
226+ @app .event ("member_left_channel" )
227+ async def handle_member_left_channel (say ):
228+ await say ("What's up?" )
229+
230+ timestamp , body = str (int (time ())), json .dumps (join_event_body )
231+ request = AsyncBoltRequest (
232+ body = body , headers = self .build_headers (timestamp , body )
233+ )
234+ response = await app .async_dispatch (request )
235+ assert response .status == 200
236+ assert self .mock_received_requests ["/auth.test" ] == 1
237+
238+ timestamp , body = str (int (time ())), json .dumps (left_event_body )
239+ request = AsyncBoltRequest (
240+ body = body , headers = self .build_headers (timestamp , body )
241+ )
242+ response = await app .async_dispatch (request )
243+ assert response .status == 200
244+
245+ await asyncio .sleep (1 ) # wait a bit after auto ack()
246+ # The listeners should be executed
247+ assert self .mock_received_requests .get ("/chat.postMessage" ) == 2
248+
249+ @pytest .mark .asyncio
250+ async def test_joined_left_events (self ):
251+ app = AsyncApp (client = self .web_client , signing_secret = self .signing_secret ,)
252+ app .event ("reaction_added" )(whats_up )
253+
254+ join_event_body = {
255+ "token" : "verification_token" ,
256+ "team_id" : "T111" ,
257+ "enterprise_id" : "E111" ,
258+ "api_app_id" : "A111" ,
259+ "event" : {
260+ "type" : "member_joined_channel" ,
261+ "user" : "W111" , # other user
262+ "channel" : "C111" ,
263+ "channel_type" : "C" ,
264+ "team" : "T111" ,
265+ "inviter" : "U222" ,
266+ },
267+ "type" : "event_callback" ,
268+ "event_id" : "Ev111" ,
269+ "event_time" : 1599616881 ,
270+ "authed_users" : ["W111" ],
271+ }
272+
273+ left_event_body = {
274+ "token" : "verification_token" ,
275+ "team_id" : "T111" ,
276+ "enterprise_id" : "E111" ,
277+ "api_app_id" : "A111" ,
278+ "event" : {
279+ "type" : "member_left_channel" ,
280+ "user" : "W111" , # other user
281+ "channel" : "C111" ,
282+ "channel_type" : "C" ,
283+ "team" : "T111" ,
284+ },
285+ "type" : "event_callback" ,
286+ "event_id" : "Ev111" ,
287+ "event_time" : 1599616881 ,
288+ "authed_users" : ["W111" ],
289+ }
290+
291+ @app .event ("member_joined_channel" )
292+ async def handle_member_joined_channel (say ):
293+ await say ("What's up?" )
294+
295+ @app .event ("member_left_channel" )
296+ async def handle_member_left_channel (say ):
297+ await say ("What's up?" )
298+
299+ timestamp , body = str (int (time ())), json .dumps (join_event_body )
300+ request = AsyncBoltRequest (
301+ body = body , headers = self .build_headers (timestamp , body )
302+ )
303+ response = await app .async_dispatch (request )
304+ assert response .status == 200
305+ assert self .mock_received_requests ["/auth.test" ] == 1
306+
307+ timestamp , body = str (int (time ())), json .dumps (left_event_body )
308+ request = AsyncBoltRequest (
309+ body = body , headers = self .build_headers (timestamp , body )
310+ )
311+ response = await app .async_dispatch (request )
312+ assert response .status == 200
313+
314+ await asyncio .sleep (1 ) # wait a bit after auto ack()
315+ # The listeners should be executed
316+ assert self .mock_received_requests .get ("/chat.postMessage" ) == 2
317+
142318
143319app_mention_body = {
144320 "token" : "verification_token" ,
0 commit comments