Here is the report I promised on this thread So I just set up #BlueHat to automatically send invites for users who register via our Typeform to the chat.
Slack's Api and Typeform Api are both well documented which is nice. Since my language of preference is python I'm going to show you how I did it. If you want PHP click here, got the idea from levels
I've gone ahead and declared all the variables you are going to need. All you need to do is get your api keys
Note: your typeformFormId is the one on the forum, so on after the join click on #BlueHat it takes the visitor this url https://hashtagbluehat.typeform.com/to/Henu8s as you can see the typeformFormId is "Henu8s"
I have also used pony as the database management. I know it might be over kill, but we need to parse the type form json to see if we already sent a invite to the visitor.
invites.py
import requests
from pony.orm import *
import datetime
db = Database('sqlite', 'db.sqlite', create_db=True)
class User(db.Entity):
name = Optional(unicode)
email = Required(unicode)
db.generate_mapping(create_tables=True)
#typeform stuff
typeformApiKey = 'put_your_typeform_key_here'
typeformFormId='put_your_typeform_id_here'
typeformEmailField='put_textfield_from_typeform_json_for_email'
typeformNameField='put_textfield_from_typeform_json_for_name'
#slackstuff
slackHostName='hashtagbluehat' #put your slack subdomain here
slackAutoJoinChannels = '' #if there are any channels you want the user put them here
epoch = datetime.datetime.utcfromtimestamp(0)
slackAuthToken = 'put_your_slack_api_key_here'
#hitting up typeform for emails, sending invites to slack as scrolling through list
rtypeform = requests.get("https://api.typeform.com/v0/form/%s?key=%s&completed=true" % (typeformFormId, typeformApiKey))
data = rtypeform.json()
#scrolling through typeform json checking to see if user already sent invite, if not sending invite
for item in data['responses']:
email = item['answers'][typeformEmailField]
name = item['answers'][typeformNameField]
with db_session:
if not User.exists(email=email):
try:
slackInvite = requests.post("https://%s.slack.com/api/users.admin.invite?t=%s" % (slackHostName, epoch), data = {"token":slackAuthToken, "email":email, "name":name})
except:
continue
user = User(email=email, name=name)
commit()
else:
continue
Now that we have this set up, we need to automate so it runs, I'm using Ubuntu for the server so we can just set up a cron job bash file
run.sh
#!/bin/sh
/home/www/env/bin/python /path/to/your/project/invites.py
once we have made that file we run
sudo crontab e
In there at the bottom of the file we put in this so it runs once every 30 minutes
*/30 * * * * /path/to/your/project/cron/run.sh
And that's it! You now have a typeform user signup with automated invites sent out.