user_col = user_col.strip() if user_col and rowmap[user_col]: user_name = rowmap[user_col].lower() if include_phone: phone_number = format_phone_number(people_phone_numbers[user_name]) else: phone_number = '' try: slack_username = sh.get_username_for_fullname(user_name) except: print('Failed to get Slack username for ' + user_name) exit(1) msg += user_col + ': ' + '@' + sh.get_username_for_fullname(user_name) + ' ' + phone_number + '\n' if testing_slack_channel is not None: slack_channels = [ testing_slack_channel ] else: slack_channels = [s.strip() for s in slack_channels.split(',')] if len(msg) > 0: for idx, slack_channel in enumerate(slack_channels): msg_to_send = msg # Only ack first one if idx == 0 and ack: msg_to_send += 'If you were mentioned, please acknowledge by reacting to this message with a :' + get_random_emoji() + ':\n' sh.send_message(msg_to_send, SLACK_USERNAME, slack_channel, SLACK_ICON_URL) else: print('No message for ', tab, message)
CREDENTIALS_FILE = get_conf_or_env( "CREDENTIALS_FILE", config_data, "credentials.json" ) SLACK_TOKEN = get_conf_or_env("SLACK_TOKEN", config_data) sh = SlackHelper(SLACK_TOKEN) gh = GSheetHelper(CREDENTIALS_FILE) rows = gh.get_rows("Quiz questions", "Questions") row = random.choice(rows) answer_choices = [row[x] for x in ("Answer", "Choice A", "Choice B", "Choice C")] random.shuffle(answer_choices) msg = row["Question"] + "\n" + "\n".join(answer_choices) sh.send_message( msg, "TEST TEST", "#tmp-slack-api", "http://dan.triplelift.net/q.png" ) msg = ( '/poll "' + row["Question"] + '" ' + " ".join('"' + x + '"' for x in answer_choices) ) sh.execute_command( msg, "TEST TEST", "#tmp-slack-api", "http://dan.triplelift.net/q.png" )
#! /usr/bin/env python import config from slack_helper import SlackHelper import sys from datetime import datetime if __name__ == "__main__": if len(sys.argv) != 3: print "Please specify channel and message" exit() channel_name = sys.argv[1].replace("#", "") message = sys.argv[2] sh = SlackHelper(config.SLACK_TOKEN) channel_members = sh.get_channel_members("#" + channel_name) for member_id in channel_members: username = sh.get_name_by_id(member_id) print "Sending to {0}".format(username) print sh.send_message( msg=message, username=None, as_user=True, channel=member_id, icon_url=None, )
logging.basicConfig(format=FORMAT, level=logging.INFO) logger = logging.getLogger('quiz') if __name__ == '__main__': config_data = read_config_file('config.env') CREDENTIALS_FILE = get_conf_or_env('CREDENTIALS_FILE', config_data, 'credentials.json') SLACK_TOKEN = get_conf_or_env('SLACK_TOKEN', config_data) sh = SlackHelper(SLACK_TOKEN) gh = GSheetHelper(CREDENTIALS_FILE) rows = gh.get_rows('Quiz questions', 'Questions') row = random.choice(rows) answer_choices = [ row[x] for x in ('Answer', 'Choice A', 'Choice B', 'Choice C') ] random.shuffle(answer_choices) msg = row['Question'] + '\n' + '\n'.join(answer_choices) sh.send_message(msg, 'TEST TEST', '#tmp-slack-api', 'http://dan.triplelift.net/q.png') msg = '/poll "' + row['Question'] + '" ' + ' '.join( '"' + x + '"' for x in answer_choices) sh.execute_command(msg, 'TEST TEST', '#tmp-slack-api', 'http://dan.triplelift.net/q.png')