Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting 404 with the sample #26

Open
RoboDonut opened this issue Dec 10, 2015 · 11 comments
Open

getting 404 with the sample #26

RoboDonut opened this issue Dec 10, 2015 · 11 comments

Comments

@RoboDonut
Copy link

404 with the sample if i drop in @app.route('/') i get a page (but no response). i'm new to flask so any help is awesome.

@halfcrazy
Copy link
Member

@RoboDonut Have you configured the callback url, in the example we use app.config['SLACK_CALLBACK'] = '/slack_callback', so you can post to this url instead of / root path if u are trying the example in the readme.

@RoboDonut
Copy link
Author

yes, i set to app.config['SLACK_CALLBACK'] = '/flaskyou' flaskyou is the slash command i set in slack

@halfcrazy
Copy link
Member

@RoboDonut Could you post your full code here?

@RoboDonut
Copy link
Author

Yeah

@RoboDonut
Copy link
Author

from flask import Flask

from flask_slackbot import SlackBot


app = Flask(__name__)
app.config['SLACK_TOKEN'] = 'xoxs-10205404050-xxxxxxxxxxx-xxxxxxxxxx-0483ff0e8a' #TOKEN FROM API PAGE
# if you need to use slacker you should give a slack chat token
app.config['SLACK_CHAT_TOKEN'] = 'Deyt1lhPPoR2HoKiZt2TGkFr' # Token from the slash command
app.config['SLACK_CALLBACK'] = '/flaskyou' # the slash command
app.debug = True
slackbot = SlackBot(app)


def fn1(kwargs):
    return {'text': '!' + kwargs['text']}


def fn4(kwargs):
        return {'text': '!' + kwargs['text'], 'private': True}


def fn2(kwargs):
    slackbot.slack.chat.post_message('#general', 'hello from slacker handler')
    return None


def fn3(text):
    return text.startswith('!')


slackbot.set_handler(fn1)
slackbot.filter_outgoing(fn3)


if __name__ == "__main__":
    app.run(host='0.0.0.0')

@RoboDonut
Copy link
Author

if i add in a typical @app.route('/') i dont get the 404 and the / command returns hello world

...
app.debug = True
slackbot = SlackBot(app)
@app.route('/')
def hello_world():
    return 'Hello World!'

def fn1(kwargs):
    return {'text': '!' + kwargs['text']}
...

@RoboDonut
Copy link
Author

The URL I set in the slash command is theoasis.mydissent.net:5000

I believe I've tested both get a post methods

@halfcrazy
Copy link
Member

@RoboDonut Oops, It seems you don't use the post method, the message was posted by slack official server to your end point, so if you want to simulate this behavior you need to send post. You can use postman(a chrome extension) or curl or httpie.

Here's the data we get from the post. You may construct the request with those fields.

token = request.form.get('token')
team_id = request.form.get('team_id')
team_domain = request.form.get('team_domain')
channel_id = request.form.get('channel_id')
channel_name = request.form.get('channel_name')
timestamp = request.form.get('timestamp')
user_id = request.form.get('user_id')
user_name = request.form.get('user_name')
text = request.form.get('text')
trigger_word = request.form.get('trigger_word')

curl -d 'token=balabala&team_id=balabala ....' http://theoasis.mydissent.net:5000/flaskyou

@RoboDonut
Copy link
Author

even when i set the command to post it still fails. :(

@halfcrazy
Copy link
Member

@RoboDonut

~  curl -d 'text=1' http://theoasis.mydissent.net:5000/flaskyou
{
  "text": "!1"
}%                   

I try to post an empty body to your server, and it returns something may helpful to you.
It demonstrate that the post method already works, although the data i post was not valid...

I note you are using windows, so your system may not have curl, you can use postman instead,

@RoboDonut
Copy link
Author

thank you for all your fast help. i'll keep working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants