question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bot to save a pdf uploaded by the user to host computer

See original GitHub issue

Hello. I would like to create a bot that can read in an uploaded file (pdf) uploaded by the user and save it to a server (for now on the host computer). I am thinking the files.info method might work, but I am not sure how to get to the specific file. Could you post an example of how to do this?

import os
from slack_bolt import App

app = App(
    token= os.environ.get('SLACK_BOT_TOKEN'),
    signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)


# # # LISTENING FUNCTIONS # # # 
# This will matc h any message that contains "Hi!"
@app.message("Hi!")
def initial_message_func(message, say):
	say("please upload your pdf")


@app.message("")
def message_to_sam_func(client,message):
    client.file.info(file = file_ID)    #not sure how to get file_ID
                                        

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
mae5357commented, Mar 30, 2021

Thank you for the help. Posted final code in case others had issues

@app.event("file_shared")
def file_func(payload, client, ack):
    ack()

    #get the file id every time someone uploads a pdf
    my_file = payload.get('file').get('id')
    
    #get the json using files_info
    url = client.files_info(file = my_file).get('file').get('url_private')
    file_name = client.files_info(file = my_file).get('file').get('title')

    # save file
    resp = requests.get(url, headers={'Authorization': 'Bearer %s' % token})
    save_file = Path(file_name)
    save_file.write_bytes(resp.content)
0reactions
mauriciograciacommented, Mar 24, 2022

In case you need your slack bot to recieve a file shared by DM here a starting point

@app.event("message")
def handle_message_events(body, logger):
    # Unhandled request({'type': 'event_callback', 'event': {'type': 'message', 'subtype': 'file_share'}})
    logging.warning(body)

You need ngrok to be running (when in development mode) and you need to enable Event Subscriptions and configure it with the URL that ngrok generates automatically.

imagen

Keep in mind that if you restart ngrok a new URL will be generated

If you want a stable URL you need to pay for ngrok or set another type of forwarding - https://ngrok.com/docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extract Data From PDF: Convert PDF Files Into Structured Data.
At Docparser, we offer a powerful yet easy-to-use set of tools to extract data from PDF files. Our solution was designed for the...
Read more >
How to Add PDF Files to Websites - Lifewire
Use your web host's file upload program to upload PDF files to your website. If they don't offer one, use an FTP program....
Read more >
Using Upload Document action
The Upload Document action enables you to upload a document with IQ Bot. IQ Bot extracts fields from the document and exports them...
Read more >
files.upload method - Slack API
This method allows you to create or upload an existing file. You must provide either a file or content parameter. The content of...
Read more >
How to save one page of a PDF - Adobe
Drag and drop your file. Once it uploads, use the scissors tool to indicate which page you want to separate out. Click continue....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found