def slack_tiles(channel, search_term, title, title_url, image_url): attachments_json = [ { "title": title.values[0], "title_link": title_url.values[0], "image_url": image_url.values[0] }, { "title": title.values[1], "title_link": title_url.values[1], "image_url": image_url.values[1] }, { "title": title.values[2], "title_link": title_url.values[2], "image_url": image_url.values[2] } ] # Send a message with the above attachment, asking the user if they want coffee slack_client.api_call( "chat.postMessage", channel=channel, text='Recommendations for "' + str(search_term) + '"', attachments=attachments_json )
def output_command(channel, slack_output): """ Output bot command via the slack channel """ slack_client.api_call("chat.postMessage", channel=channel, text=slack_output)
def file_upload(channel, filename): with open(filename,'rb') as file_content: slack_client.api_call( "files.upload", channels=channel, file=file_content )
def slack_tiles(channel, search_term, title, title_url, image_url): attachments_json = [ { "title": title.values[0], "title_link": title_url.values[0], "image_url": image_url.values[0] }, { "title": title.values[1], "title_link": title_url.values[1], "image_url": image_url.values[1] }, { "title": title.values[2], "title_link": title_url.values[2], "image_url": image_url.values[2] } ] slack_client.api_call( "chat.postMessage", channel=channel, text='Recommendations for "' + str(search_term) + '"', attachments=attachments_json )
def message_buttons(channel, button, url, search_term): #print("-------------------------------------message_buttons-------------------------------------") attachments_json = [ { "text": " ", "fallback": "You didn't make a selection", "callback_id": "code_search", "color": "#3AA3E3", "attachment_type": "default", "actions": [ { "name": "code_link", "text": "1. " + button.values[0], "type": "button", "url": url.values[0] }, { "name": "code_link", "text": "2. " + button.values[1], "type": "button", "url": url.values[1] }, { "name": "code_link", "text": "3. " + button.values[2], "type": "button", "url": url.values[2] }, { "name": "code_link", "text": "4. " + button.values[3], "type": "button", "url": url.values[3] }, { "name": "code_link", "text": "5. " + button.values[4], "type": "button", "url": url.values[4] } ] } ] # Send a message with the above attachment, asking the user if they want coffee slack_client.api_call( "chat.postMessage", channel=channel, text=search_term, attachments=attachments_json )
def file_upload(channel, filename): #slack_client.api_call('files.upload', channels=channel, filename=filename, file=open(filename, 'rb')) #print("-------------------------------------file_upload-------------------------------------") #print("trying") print('filename before with::: ',filename) print('channel before with::: ',channel) with open(filename,'rb') as file_content: print('filename inside with::: ',filename) print('channel inside with::: ',channel) slack_client.api_call( "files.upload", channels=channel, file=file_content )
def message_buttons(channel, button, url, search_term): attachments_json = [ { "text": " ", "fallback": "You didn't make a selection", "callback_id": "code_search", "color": "#3AA3E3", "attachment_type": "default", "actions": [ { "name": "code_link", "text": "1. " + button.values[0], "type": "button", "url": url.values[0] }, { "name": "code_link", "text": "2. " + button.values[1], "type": "button", "url": url.values[1] }, { "name": "code_link", "text": "3. " + button.values[2], "type": "button", "url": url.values[2] }, { "name": "code_link", "text": "4. " + button.values[3], "type": "button", "url": url.values[3] }, { "name": "code_link", "text": "5. " + button.values[4], "type": "button", "url": url.values[4] } ] } ] slack_client.api_call( "chat.postMessage", channel=channel, text=search_term, attachments=attachments_json )
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: context = {} session_df = session_df.append( { 'timestamp': start_timestamp,
def output_command(channel,slack_output): slack_client.api_call( "chat.postMessage", channel=channel, text=slack_output )