Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
projet i2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Samy Haffoudhi
projet i2
Commits
2b5bda16
Commit
2b5bda16
authored
Dec 11, 2021
by
Samy Haffoudhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring et creation de l'app
parent
c969bf59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
17 deletions
+29
-17
app.py
bot/app.py
+13
-17
message_auto.py
bot/message_auto.py
+16
-0
No files found.
bot/app.py
View file @
2b5bda16
import
os
import
os
from
slack_bolt
import
App
from
slack_sdk
import
WebClient
app
=
App
(
from
slack_sdk.errors
import
SlackApiError
token
=
os
.
environ
.
get
(
"SLACK_BOT_TOKEN"
),
signing_secret
=
os
.
environ
.
get
(
"SLACK_SIGNING_SECRET"
)
)
client
=
WebClient
(
token
=
os
.
environ
.
get
(
"SLACK_BOT_TOKEN"
))
@
app
.
event
(
"channel_created"
)
def
join_channel
(
event
,
client
):
channel
=
event
[
'channel'
]
if
channel
[
'name'
][
0
]
==
'2'
:
client
.
conversations_join
(
channel
=
channel
[
'id'
])
client
.
chat_postMessage
(
channel
=
channel
[
'id'
],
text
=
"Salut !"
)
try
:
if
__name__
==
"__main__"
:
result
=
client
.
conversations_list
(
types
=
"public_channel, private_channel"
)
app
.
start
(
port
=
int
(
os
.
environ
.
get
(
"PORT"
,
3000
)))
for
response
in
result
:
for
channel
in
result
[
"channels"
]:
if
(
channel
[
"name"
][
0
]
==
'2'
)
and
(
not
channel
[
"is_archived"
]):
try
:
client
.
conversations_join
(
channel
=
channel
[
"id"
])
except
:
pass
client
.
chat_postMessage
(
channel
=
channel
[
"id"
],
text
=
"Salut ! Ceci est un test :grin:"
)
# print(channel["name"])
except
SlackApiError
as
e
:
print
(
f
"Error: {e}"
)
bot/message_auto.py
0 → 100644
View file @
2b5bda16
import
os
from
slack_sdk
import
WebClient
from
slack_sdk.errors
import
SlackApiError
client
=
WebClient
(
token
=
os
.
environ
.
get
(
"SLACK_BOT_TOKEN"
))
try
:
result
=
client
.
conversations_list
(
types
=
"public_channel, private_channel"
)
for
response
in
result
:
for
channel
in
result
[
"channels"
]:
if
(
channel
[
"name"
][
0
]
==
'2'
)
and
(
not
channel
[
"is_archived"
]):
client
.
chat_postMessage
(
channel
=
channel
[
"id"
],
text
=
"Salut ! Ceci est un test :grin:"
)
except
SlackApiError
as
e
:
print
(
f
"Error: {e}"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment