Closed hans0801 closed 6 months ago
On api.slack.com/apps, under Features -> Event Subscriptions, what events is your app subscribed to?
If you are listening for messages, then your app needs to subscribe to the relevant event to get notified of them. In this case, since you are listening for specific messages using the @app.message
decorator, you will need to subscribe to the message.channels
event. This event also requires that your app request the channels:history
scope.
Hi @filmaj ,
Thanks for your kindly response. Yes sure I already subscribed those events but the result is still same.
Thanks
On Fri, Jan 5, 2024, 02:20 Fil Maj @.***> wrote:
On api.slack.com/apps, under Features -> Event Subscriptions, what events is your app subscribed to?
If you are listening for messages, then your app needs to subscribe to the relevant event to get notified of them. In this case, since you are listening for specific messages using the @app.message decorator, you will need to subscribe to the message.channels event https://api.slack.com/events/message.channels. This event also requires that your app request the channels:history scope https://api.slack.com/scopes/channels:history.
— Reply to this email directly, view it on GitHub https://github.com/slackapi/bolt-python/issues/1008#issuecomment-1877635996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGZ3BIHBBKWP5SN6KLBFBC3YM36GLAVCNFSM6AAAAABBMZ6X6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXGYZTKOJZGY . You are receiving this because you authored the thread.Message ID: @.***>
Here is my capture regarding the listening messages scope:
Is your app installed to the workspace you are sending the message to? Is the app invited into the channel you are sending your hello
message in?
Another thing to try is to set your app in debug mode to see if there are any incoming events hitting your app or not, as per these docs: https://slack.dev/bolt-python/concepts#logging
Hi @filmaj , Yes my app already installed on my workspace and already invited to the channel.
I already added "logger" on my code but still nothing happened.
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
# Initializes your app with your bot token and socket mode handler
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
# Listens to incoming messages that contain "hello"
@app.message("hello")
def message_hello(message, say):
# say() sends a message to the channel where the event was triggered
say(
blocks=[
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Hey there <@{message['user']}>!"},
"accessory": {
"type": "button",
"text": {"type": "plain_text", "text": "Click Me"},
"action_id": "button_click"
}
}
],
text=f"Hey there <@{message['user']}>!"
)
logger.debug(message)
@app.action("button_click")
def action_button_click(body, ack, say):
# Acknowledge the action
ack()
say(f"<@{body['user']['id']}> clicked the button")
# Start your app
if __name__ == "__main__":
handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
handler.start()
You did not add the debug logging mode I linked to, just debug logged a message from within your message handler. Please review my link from earlier to turn debug logging generally on for the app. It should result in much more logging output on bootup.
Hi @filmaj , apologies my bad for not enabled the debug mode. I already enabled the debug mode and the result is like this:
I saw no error found, because the result message is:
INFO:slack_bolt.App:A new session has been established (session id: 0cd15778-b136-41b0-9c0d-388ca6e5b3b8)
INFO:slack_bolt.App:⚡️ Bolt app is running!
INFO:slack_bolt.App:Starting to receive messages from a new connection (session id: 0cd15778-b136-41b0-9c0d-388ca6e5b3b8)
DEBUG:slack_bolt.App:on_message invoked: (message: {"type":"hello","num_connections":4,"debug_info":{"host":"applink-4","build_number":42,"approximate_connection_time":18060},"connection_info":{"app_id":"A06C15UL879"}})
DEBUG:slack_bolt.App:A new message enqueued (current queue size: 1)
DEBUG:slack_bolt.App:A message dequeued (current queue size: 0)
DEBUG:slack_bolt.App:Message processing started (type: hello, envelope_id: None)
DEBUG:slack_bolt.App:Message processing completed (type: hello, envelope_id: None)
Something is off here with tokens or workspace membership or channel membership, because in debug mode, all events that the app is subscribed that are pushed to the app should be logged out to your console.
My theory is one of these things is not true:
app_id
as returned by the auth.test
API (you can see this is one of the first logs in your debug log output when you start the app, where it says "sending a request to slack.com/api/auth.test", the response contains an app_id
) is not the same app installed to your workspace./invite @yourappname
in the channel.Another way you can try to test these assumptions out:
SLACK_BOT_TOKEN
, based on your code).chat.postMessage
API reference document and flip the tab at the top to the 'tester' (this URL: https://api.slack.com/methods/chat.postMessage/test). Under the "Arguments" tab of the API tester, enter the following arguments:
text
argument and enter some message text, e.g. "hello from API tester"Hi @filmaj ,
Thank you so much for your kindly explaination and information regarding the test case. Yes, I already tried the way that you gave to us. The result is successfull for sent the messages to my channel, here is the log and capture:
{
"ok": true,
"channel": "XXXXXXXXXXX",
"ts": "1704470831.292129",
"message": {
"bot_id": "XXXXXXXXXXX",
"type": "message",
"text": "hello from API tester",
"user": "XXXXXXXXXXX",
"ts": "1704470831.292129",
"app_id": "XXXXXXXXXXX",
"blocks": [
{
"type": "rich_text",
"block_id": "MCe0",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "hello from API tester"
}
]
}
]
}
],
"team": "XXXXXXXXXXX",
"bot_profile": {
"id": "B06CTH53EHX",
"app_id": "XXXXXXXXXXX",
"name": "XXXXXXXXX Bot",
"icons": {
"image_36": "https://avatars.slack-edge.com/2024-01-04/6416303112150_1d84c71817b9bd5d0f6b_36.png",
"image_48": "https://avatars.slack-edge.com/2024-01-04/6416303112150_1d84c71817b9bd5d0f6b_48.png",
"image_72": "https://avatars.slack-edge.com/2024-01-04/6416303112150_1d84c71817b9bd5d0f6b_72.png"
},
"deleted": false,
"updated": 1704368181,
"team_id": "XXXXXXXXXXX"
}
}
}
It's weird, any idea?
Thanks
I am at a complete loss then 🤷
At this point I am shooting in the dark and guessing, but some things to try to get a better understanding of what is happening:
app_mention
event, and again in a public channel that both the user mentioning the app and the app are present in, try mentioning the app in a message. I bring this up as an avenue for testing because with your app in debug mode, you should at the very minimum see an incoming event payload show up in your app logs for any event the app is subscribed to - even if your app event handlers are not handling the event. To me this is the first step in understanding what is going on: we need to ensure your app can receive events it is subscribed to.Again, I am just listing out different things to try but at this point there is no logic behind this. Sorry 😞
Hi @filmaj , Thank you so much for your kindly explaination and information. After a long way for trying another options. I can view the error message. The message is like this:
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/chat.postMessage)
The server responded with: {'ok': False, 'error': 'not_allowed_token_type'}
have you ever met those messages or case? Thanks
@hans0801 that error means you are not using a user token or a bot token when trying to post a message using the postMessage API. Those are the only two tokens that are accepted.
Hi @filmaj , ah i see, thank you so much for your kindly help and explaination. Now it's working like a charm. After i re-create the bot token that i Used. Thanks
The
slack_bolt
versionPython runtime version
Python 3.11.3
OS info
Steps to reproduce:
(Share the commands to run, source code, and project settings (e.g., setup.py))
Enable socket mode on Slack App![Screenshot 2024-01-04 at 19 15 22](https://github.com/slackapi/bolt-python/assets/28553376/fa0b0a81-958d-4534-b089-dc77e1930546)
source .venv/bin/activate
python slackbolt.py
Here is my code:
Expected result:
The python slack bolt will response the message on channel when someone write "hello"
Actual result:
Nothing happened. Just showing "Bolt app is running!"
Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.