Unhandled request ({'type': 'event_callback', 'event': {'type': 'message'}}) --- [Suggestion] You can handle this type of event with the following listener function:

See original GitHub issue

I wanted to test my script with a simple message and I get the error mentioned in the title, my main goal is to read what the user has sent in the main chat and then send the open and close price of a given stock using yfinance. I was also having hard time finding the home page for my server as I tried one of the example code given in the documentation and I don’t see if being dispalyed any where in my channel, do I need to make a new channel for that.

CODE:

load_dotenv()
env_path = Path('.')/ '.env'
load_dotenv(dotenv_path=env_path)
app = Flask(__name__)

app = App(
    token=os.environ.get("SLACK_TOKEN"),
    signing_secret=os.environ.get("SIGNING_SECRET")
)

if __name__ == "__main__":
    app.start(port=int(os.environ.get("PORT", 3000)))


@app.message("knock knock")
def ask_who(message, say):
    say("_Who's there?_")

I am also running the ngrok local server as well, I am very new to this so most of the documentation was confusing to me

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
utsangcommented, Jan 6, 2022

Thank you very much for responding, I think this answers most of my questions. So I have the following code:

tickerWant = text
data = yf.download(tickerWant, start="2021-09-5", end=d4)
    
data.to_csv(rf'C:\work\demo\data\{tickerWant}.csv')

in my case I want tickerWant to be whatever the ticker the user sends, so I can just do this correct:

def do_something(text):
      tickerWant = text
      data = yf.download(tickerWant, start="2021-09-5", end=d4)
      data.to_csv(rf'C:\work\demo\data\{tickerWant}.csv') 

and then use the def print_message function? EDIT: Problem has been fixed thank you very much for your patience in helping me 😃

0reactions
misscodedcommented, Jan 6, 2022

since I need to get that value is there a command, can I use b = event.get(‘text’) in this case or is there a specific way? I am assuming that the user will only talk about tickers and use the correct format and will use a specific channel

If you mean that you want to listen for all messages that the user sends, we recommend using the @app.event('message') listener, accessing the message text as seen below:

@app.event('message')
def print_message(event):
  msg_txt = event['text']
  print(msg_txt)

To note: these message listeners will also pick up messages sent by apps, so if you want to filter those out, you can write some additional logic and return early if the event has a subtype of bot_message.

For the Home page issue, I was just confused as to what slack would consider home page

Usually, we think of the Home Tab as the “home page” for apps. This is where your users can find all useful and pertinent information related to your app. You can learn more about the Home Tab here.

As for a “home channel”, it’s entirely up to you which channel(s) you add your bot to! 🙂

Also is there a way use the text that user types in outside of the function as well? I am very new to coding as well

You can definitely do so! One way to accomplish this is by using a helper function. This allows you to pass the message text elsewhere (outside of the listener function) to process.

The below snippet is an edit of the above and might be a good place for you to start from:

@app.event('message')
def print_message(event):
  msg_txt = event['text']
  do_something(msg_txt)

def do_something(text):
  print(f"Doing something with {text}!")

Let us know if the above resolves the issue(s) raised!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bolt for Python - Slack Platform Developer Tools
To listen to messages that your app has access to receive, you can use the message() method which filters out events that aren't...
Read more >
ASP.NET Core Blazor event handling - Microsoft Learn
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >
AutoCompleteTextView - Android Developers
android:completionThreshold, Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu.
Read more >
slackapi/bolt-python v1.6.0 on GitHub - NewReleases.io
App:Unhandled request ({'type': 'event_callback', 'event': {'type': 'message'}}) --- [Suggestion] You can handle this type of event with the following ...
Read more >
How To Send Parameters To Event CallBacks In Blazor
The following is the 5 step approach, this will help you to understand ... "OnProductSelected" is a type of EventCallback which is an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found