I belong to an organization called kosen11s
that has only a metamorphosis with a name like a certain super-dimensional soccer anime team.
At first, there was a lot of noise saying "_Automation! Automation! Automation !!!!", so I automated it.
(I'm sorry for Level Five !!!)
kosen11s/slack_welcome_kosen11s
Take a look at the GitHub repository! !! I want to make it feel like
Python 3.5.1 pip 8.1.2
$ git clone https://github.com/kosen11s/slack_welcome_kosen11s.git
$ cd slack_welcome_kosen11s
$ pip install -r requiredments.txt
I will omit the API key etc. of Slack this time! !! I'm sorry!
run.py
from slackbot.bot import Bot
import slackbot_settings
if __name__ == "__main__":
bot = Bot()
bot.run()
I don't know if it makes sense to keep this running all the time, but isn't it nice to have a logged-in user?
welcome_bot.py
from slacker import Slacker
import json, requests
import slackbot_settings
welcomeMessage = """
Welcome to kosen11s:tada::tada::tada::tada:\n
First of all#Introduce yourself briefly on the profile channel:heart:\n
Other#github , #muscle , #nsfw , #There is skype! Please enter properly:raryosu:\n
And this is the last! Please fill in the skill sheet linked below!\n
The URL is Hi, Mi, Tsu ♡\n
Nice to meet you:octocat:
"""
class Member(object):
memberCount = 0
def setMember(self):
data = getJson()
self.memberCount = len(data['channel']['members'])
def getJson():
url = 'https://slack.com/api/channels.join'
parameters = {
'token' : slackbot_settings.API_TOKEN_TEAM,
'name' : 'random'}
r = requests.get(url, params = parameters)
data = json.loads(r.text)
mem = Member()
if mem.memberCount == 0:
mem.memberCount = len(data['channel']['members'])
return data
def welcomePost(user):
slack = Slacker(slackbot_settings.API_TOKEN)
slack.chat.post_message(
'@' + user,
'Hi! ' + user + " " + welcomeMessage,
as_user = True,
link_names = 1
)
if __name__ == '__main__':
mem = Member()
mem.setMember()
while True:
jsonChannel = getJson()
if mem.memberCount < len(jsonChannel['channel']['members']):
print(mem.memberCount)
mem.memberCount = len(jsonChannel['channel']['members'])
url = 'https://slack.com/api/users.info'
parameters = {
'token' : slackbot_settings.API_TOKEN_TEAM,
'user' : jsonChannel['channel']['members'][0]}
r_2 = requests.get(url, params = parameters)
jsonUser = json.loads(r_2.text)
welcomePost(jsonUser['user']['name'])
THE is suitable.
slackbot_settings.py
API_TOKEN = 'xoxb-***********-************************'
API_TOKEN_TEAM = 'xoxp-***********-***********-***********-**********'
What if you run it with this? ?? ??
A message came to me (directly specifying the user for testing) who was transformed into a new person like this! !! !!
For some reason, I stuck in one leg before the chatbot got hot, but why don't you try making a SlackBOT or something easily?
Recommended Posts