Example #1
0
	def send():
		slackhelper = SlackHelper()
		slackhelper.post_message('Morning, where are you located today?\nPlease write your location in one line (city, building, floor...)\nIf you need to search for a user, use his username with the @.\nThank you! :smile:', 'DN036B2PJ')
		response_body = {'text': ':)'}
		response = jsonify(response_body)
		response.status_code = 200
		return response
Example #2
0
	def sendall():
		slackhelper = SlackHelper()
		request = slackhelper.get_users_in_channel()
		if request['ok']:
			for item in request['members']:
				print(item['id'])
				slackhelper.post_message('Morning, where are you located today?\nPlease write your location in one line (city, building, floor...)\nIf you need to search for a user, use his username with the @.\nThank you! :smile:', item['id'])
		
		response_body = {'text': ':)'}
		response = jsonify(response_body)
		response.status_code = 200
		return response
Example #3
0
    def test_post_message_works(self, mock_slack_api_call):
        mock_slack_api_call.return_value = {
            "ok": "true",
            "channel": "Eat",
            "message": "Hi"
        }

        slack_helper = SlackHelper()

        assert slack_helper.post_message(message="Hi",
                                         channel="Roger").get("ok") == "true"
        assert slack_helper.post_message(
            message="Hi", channel="Roger").get("channel") == "Eat"
        assert slack_helper.post_message(
            message="Hi", channel="Roger").get("message") == "Hi"
Example #4
0
	def reaction():
		type = request.data.get('type')
		event = request.data.get('event')
		user_id = event['user']
		channel = event['channel']
		text = event['text']

		if type == 'url_verification':
			response_body = request.data.get('challenge')
		else:
			response_body = 'Hi!'
			if not user_id == bot_id:
				slackhelper = SlackHelper()
				slack_user_info = slackhelper.user_info(user_id)
				user_name = slack_user_info['user']['name']
				clean_user_name = slack_user_info['user']['profile']['real_name_normalized']
				words_to_check = [' close to ',' near ',' next to ',' beside ',' in front of ',' behind ',' on ',' in ',' at ',' on ',' top of ',' within ',' beneath ',' under ','building','bau','basel','kau','kaiseraugst','floor','home','wfh']
				
				print (text)
				if re.search("@(?!\W)", text):
					m = re.findall(r'[@]\w+', text)
					print(m)
					user = m[0]
					print('username: '******'user: '******'user']['profile']['real_name_normalized']
					location = redis_client.get(user[1:]) or 'The user hasn\'t set the location yet'
					if location == 'The user hasn\'t set the location yet':
						slackhelper.post_message(location, channel)
					else:
						slackhelper.post_message("%s:  %s" % (search_clean_user_name, location.decode('utf8')), channel)
				elif any(word.lower() in text.lower() for word in words_to_check):
					slackhelper = SlackHelper()
					print(user_name)
					redis_client.set(user_id, text)
					slackhelper.post_message('Thank you! :smile: I have recorded your location.\nHave a good day!', channel)
				elif 'list' in text:
					if len(redis_client.keys()) > 0:
						list = ''
						print(redis_client.keys())
						for user in redis_client.keys():
							print(user)
							print(slackhelper.user_info(user))
							name =  slackhelper.user_info(user)['user']['profile']['real_name_normalized']
							list = list + name + ': '+ redis_client.get(user).decode('utf8') + '\n'
						slackhelper.post_message(list, user_id)
					else:
						slackhelper.post_message('Sorry, there are no users registered', user_id)

				else:
					slackhelper.post_message('Sorry :disappointed:, I didn\'t understand your request.\n - If you want to add your location, please say in one line where are you located (city, building, floor...)\nIf you need to search for a user use his username with the @.\nThank you! :smile:', channel)

			else:
				print("nothing")
		response = jsonify(response_body)
		response.status_code = 200
		return response