Commit 39edf145 authored by Samy Haffoudhi's avatar Samy Haffoudhi

liste, ajout au cheannel et envoi de messages

parent 91e45f67
import os
from slack_bolt import App
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
app = App(
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("app_home_opened")
def update_home_tab(client, event, logger):
try:
# views.publish is the method that your app uses to push a view to the Home tab
client.views_publish(
# the user that opened your app's app home
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__":
app.start(port=int(os.environ.get("PORT", 3000)))
try:
result = client.conversations_list()
for response in result:
for channel in result["channels"]:
if channel["name"][0] == '2':
if not channel["is_archived"]:
client.conversations_join(channel=channel["id"])
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