Sure, you can, This is a Python Code for same:
from slack_bolt import App
from slack_sdk import WebClient
from slack_bolt.adapter.socket_mode import SocketModeHandler
import json
import os
from slack_sdk.errors import SlackApiError
@app.event("app_mention")
def handle_mention(event, say):
"""
Handles mentions of the bot and sends a table message to the Slack channel.
Parameters:
- event (dict): The event data.
- say (function): The function to send a message to the channel.
"""
# Example data
headers = ["Name", "Age", "Gender"]
rows = [["Yagna","22","Male"], ["Ray","22","Male"] ]
# Create the payload
payload = {
"blocks": [
{
"type": "table",
"rows": [
[
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": header,
"style": {
"bold": True
}
}
]
}
]
} for header in headers
]
] + [
[
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": cell
}
]
}
]
} for cell in row
] for row in rows
]
}
]
}
# Send the message to the Slack channel
try:
response = say(blocks=payload["blocks"])
print("Message sent successfully:", response)
except SlackApiError as e:
print(f"Error sending message: {e.response['error']}")