Commit 2b5bda16 authored by Samy Haffoudhi's avatar Samy Haffoudhi

refactoring et creation de l'app

parent c969bf59
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}")
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}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment