Commit f092fd98 authored by Tanguy's avatar Tanguy

Merge branch 'master' of git.centralenantesetudes.fr:shaffoudhi/projet-i2

parents ea5bb7ba 2b5bda16
import os import os
from slack_bolt import App from slack_bolt import App
app = App( app = App(
...@@ -7,56 +6,12 @@ app = App( ...@@ -7,56 +6,12 @@ app = App(
signing_secret=os.environ.get("SLACK_SIGNING_SECRET") signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
) )
@app.event("app_home_opened") @app.event("channel_created")
def update_home_tab(client, event, logger): def join_channel(event, client):
try: channel = event['channel']
# views.publish is the method that your app uses to push a view to the Home tab if channel['name'][0] == '2':
client.views_publish( client.conversations_join(channel=channel['id'])
# the user that opened your app's app home client.chat_postMessage(channel=channel['id'], text="Salut !")
user_id=event["user"],
# the view object that appears in the app home
view={
"type": "home",
"callback_id": "home_view",
# body of the view
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Bienvenue sur l'app du projet i2* :tada:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Bouton totalement inutile ci-dessous."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Clique quand même !"
}
}
]
}
]
}
)
except Exception as e:
logger.error(f"Error publishing home tab: {e}")
if __name__ == "__main__": if __name__ == "__main__":
app.start(port=int(os.environ.get("PORT", 3000))) app.start(port=int(os.environ.get("PORT", 3000)))
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