Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
114 lines (78 sloc) 3.84 KB
# -*- coding: utf-8 -*-
"""Define the Gitcoin Slack Welcome Bot flask app.
Copyright (C) 2018 Gitcoin Core
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <>.
import os
from flask import Flask, abort, jsonify, redirect, request
from slackclient import SlackClient
from slackeventsapi import SlackEventAdapter
SLACK_TEAM_ID = os.environ.get('SLACK_TEAM_ID', '')
app = Flask(__name__)
def get_default_message():
"""Return the Gitcoin Welcomebot message."""
return """
Welcome to Gitcoin! :gitcoin:
Gitcoin's mission is to *Grow Open Source*.
A few quick facts:
- We are mission driven. Check out our mission:
- We aren't an ICO. There is no Gitcoin token.
- We are a community of blockchain developers.
Here's how to get started in the community
- Say hey :wave: in #community-intros
- Join the community livestream every Friday at 5pm EST:
We believe that a great way to build new skills is to learn by doing, and Gitcoin's core product (Bounties) supports that.
Here's how to get started with bounties:
- Developer? Start by completing the contributor onboarding at and check out the open bounties at
- Repo Owner? Accelerate your dev progress by posting a bounty of your own at
- Send a tip to any github username with
We have more details in our onboarding guide at . We also have a FAQ and tutorials available at
If you have any feedback for the team, or just want to say hi, this is them:
- <@U55F2LT5L>, <@U88M8173P>, <@U8J2TK1L6>, <@U87BL3KS6>, <@U7Z23ATPB>, <@U9UKDGS01>, <@U88BVQAJD>, <@U9PL1BSAC>, <@U7J5ZPCPQ>, <@U85EFS1MM>
See you around! :spock-hand:
Welcome_bot (and the Gitcoin Team)
MESSAGE = get_default_message()
def is_request_valid(request, team_id=''):
token_valid = request.form['token'] == SLACK_VERIFICATION_TOKEN
team_id_valid = True
if team_id:
team_id_valid = request.form['team_id'] == team_id
return token_valid and team_id_valid
def index():
"""Handle the index route."""
return redirect(INDEX_REDIRECT_URL, code=302)
@app.route('/welcomebot', methods=['POST'])
def welcomebot():
if not is_request_valid(request):
return jsonify(response_type='ephemeral', text=MESSAGE)
slack_events_adapter = SlackEventAdapter(
SLACK_VERIFICATION_TOKEN, '/slack/events', app)
def new_user_welcome(event):
"""Handle team_join slack events by sending the user our welcome message."""
user = event.get('event', {}).get('user', {}).get('id', '')
if user:
channel = sc.api_call('', user=user)
channel_id = channel['channel']['id']
'chat.postMessage', channel=channel_id, unfurl_links=False, text=MESSAGE, as_user=True
# Serve the slack welcomebot flask app.
if __name__ == '__main__':