Exemplo n.º 1
0
def start_slack_event_loop():
    """Main event loop for program."""
    bot = Bot(slack_client, os.environ['SLACKBOT_ID'])
    # second delay between reading from Slack RTM firehose
    READ_WEBSOCKET_DELAY = 1
    if slack_client.rtm_connect():
        print('Bot connected and running!')
        while True:
            stream = bot.slack_client.rtm_read()
            print(stream)
            if stream and len(stream) > 0:
                bot.parse_slack_output(stream)
            time.sleep(READ_WEBSOCKET_DELAY)
    else:
        print('Connection failed.')
Exemplo n.º 2
0
# Initialize with empty value to start the conversation.
user_input = ''
context = {}
current_action = ''
follow_ind = 0
session_df = pd.DataFrame({},
                          columns=['timestamp', 'user', 'context'
                                   ])  #stores the session details of the user
# bot's user ID in Slack: value is assigned after the bot starts up
bot_id = None

# constants
RTM_READ_DELAY = 1  # 1 second delay between reading from RTM

if __name__ == "__main__":
    if slack_client.rtm_connect(with_team_state=False):
        print("Chanakya connected and running!")

        # Read bot's user ID by calling Web API method `auth.test`
        bot_id = slack_client.api_call("auth.test")["user_id"]

        while True:
            user_id, message_user, message, team, channel, start_timestamp = parse_bot_commands(
                slack_client.rtm_read(), bot_id)  #slack processing

            if message:  # If a User has typed something in Slack
                try:
                    context = json.loads(
                        session_df.loc[session_df.user == message_user +
                                       channel, 'context'].values[0])
                except:
Exemplo n.º 3
0
import json

user_input = ''
context = {}
current_action = ''
follow_ind = 0

#stores the details of user
session_df = pd.DataFrame({}, columns=['timestamp', 'user', 'context'])

bot_id = None
RTM_READ_DELAY = 1

# My program starts running here
if __name__ == "__main__":
    if slack_client.rtm_connect():
        print("MovieBot connected and running!")
        bot_id = slack_client.api_call("auth.test")["user_id"]
        while True:
            user_id, message_user, message, team, channel, start_timestamp = parse_bot_commands(
                slack_client.rtm_read(), bot_id)  #slack processing
            # If there is a message in Slack
            if message:
                try:
                    context = json.loads(
                        session_df.loc[session_df.user == message_user +
                                       channel, 'context'].values[0])
                except:
                    context = {}
                    session_df = session_df.append(
                        {