简体   繁体   中英

Slack Bot returning message from history

QUESTION

Here I am having a bot, when message with an attachment is posted in the slack channel, it should save the messages with some unique ids, and when we enter those id's in the slack channel , the bot should return that message with attachment from the chat history

(just like how the public url to a message works - https://workspace_name/archives/channel_name/token ).

If I attach an xml file in my channel, the bot should return that attachment(the specific message in which I added my attachment) from my channel's history when I type some id's associated with that message.

I am using this code : https://github.com/rampatra/jbot

At present the issue is :-

I tried to fetch the name of the file I am sharing to the channel , I was using event.getFile().getName() in SlackBot.java ( https://github.com/rampatra/jbot/blob/master/jbot-example/src/main/java/example/jbot/slack/SlackBot.java ) . and tried to display it .

  @Controller(events = EventType.FILE_SHARED) public void onFileShared(WebSocketSession session, Event event) { logger.info("File shared: {}", event); System.out.println("file id : "+event.getFileId()); System.out.println("file name :"+ event.getFile().getName()); } 

The bot should return the name of the file(1234.xml) I have shared. But it is coming as null value, but the id of the file("F........") is coming up properly.

The JSON array containing the messages is the only format that the Slack API will return for a channel history. Its the same for channel.history and conversations.history .

To get additional information like channel names, user names, etc. you will need to parse the messages you received (eg for <C12345678> for a channel) and call additional APIs to retrieve and add that information. eg conversations.info for channel name or users.info for user name. Check out this part of the Slack documentation for details on how to parse the Slack markup.

The same applies to attached and shared files. You will only get the link in the JSON array and then need to download the file by yourself. Note that you need to provide authentication for downloading private files from Slack to your app. ( see here for details):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM