Exemple #1
0
# 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:
                    context = {}
                    session_df = session_df.append(
                        {
                            'timestamp': start_timestamp,
                            'user': message_user + channel,
                            'context': json.dumps(context)
                        },
                        ignore_index=True)
Exemple #2
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("Kelly 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:
                    context = {}
                    session_df = session_df.append({'timestamp': start_timestamp, 'user': message_user+channel, 'context': json.dumps(context)}, ignore_index=True)
                    
                context,slack_output,current_action = handle_command(message,channel, message_user,context) #nlp processing
                session_df.loc[session_df.user == message_user+channel,'context'] = json.dumps(context)
                output_command(channel, slack_output) #slack processing
                conversation_id = context['conversation_id']
                
                try:
                    if context['currentIntent'] in ['anything_else']: