Giter Club home page Giter Club logo

notion-discordbot's Introduction

Notion-DiscordBot

Build StatusVisits Badge

A discord bot consuming Notion API to add and retrieve data from Notion databases.




Instructions to use the bot:

Pre-Requisites:

a) Install all the requirements using pip3 install -r requirements.txt

b) Create a discord bot using the developer platform of discord and obtain your OAuth2 token. Keep it somewhere safe

c) Go to Notion and create a new Integration https://www.notion.so/my-integrations Note the internal Integration.

d) Go to Notion and create a table like this:

4 columns where:

  • Contributor is of property type Title
  • URL of url type
  • Title of text type
  • Tag of multi-select type

e) Click on the three dots and press Open as page


f)Then press share and copy the URL. The URL will look something like this: https://www.notion.so/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?v=YYYYYYYYYYYYYYYYYYYYYYYYY

Note down the X part of the url (RED part)

This is your database id

g) Also press share again, press Invite and then click on the integration you made earlier

h) Google Drive setup: All physical files or pdf files from links are downloaded on a google drive folder of your choice.

Setup Procedure:
a) Follow the README file located here
b) Move the credentials.json file and token.json to the creds folder in the Bot folder
c) Now go to google drive and create a folder. The link of folder will be something like this https://drive.google.com/drive/folders/ID

d) Note the ID down. This will be the id of the folder where all files will be stored. Also share the folder accordingly

f) Now on the terminal of your machine:

$export DATABASE_TOKEN=<THE DATABASE TOKEN YOU NOTED DOWN>

$export AUTH_KEY=<THE INTEGRATION SECRET KEY FROM NOTION>

$export GDRIVE_FOLDER=<FOLDER ID YOU NOTED ABOVE>

$export DISCORD_AUTH=<THE SECRET TOKEN OF BOT>
If you want your prefix to be something else other than '/' then $export PREFIX=<Your Desired character>

Running Procedure:

a) Now simply go into the Bot folder and run: $python3 bot.py

b)On the discord developer site copy the OAuth2 link and paste it in the browser and invite it to a server you own/have permissions to do so

c) Bot Usage:

Adding Record:

/add <URL_YOU_WANT_TO_RECORD> => This will add a new record to your database with a misc tag

/add <URL_YOU_WANT_TO_RECORD> <TAG> => This will add a new record to your database with the <TAG> tag

For multiple tags:

/add <URL_YOU_WANT_TO_RECORD> <TAG>,<TAG1>,<TAG2>
Example:

Sample database populated by the bot:

Searching Record through tags:

/search <Tag1>

For multiple tags: /search <Tag1> <Tag2>.....<TagN>

Example:

Deleting Record through tags:

/delete <Tag 1>

For multiple tags: /delete <Tag 1> <Tag2>......<Tag N>

Example:
Intial database:

Deleting Record:

Final Database:

Uploading files

NOTE: In the below images the prefix used is: !

You can upload any file to the notion database. It can be a pdf, png, jpeg etc.
Here a png file is being uploaded
a) Drag your file to the chat in discord


b) Add comment to the file you uploaded


Here memoji and profile-pic are tags for the file

c) It will then ask the title of the file you uploaded:


d) Now the file will uploaded on the google drive folder which you mentioned above

e) The database will be updated:


f) The link will open the file in google drive



Instead of running the discord bot via python and exporting environment variables you can use our docker container.

Link to image: Docker Hub



You can also deploy this on heroku. Please follow the additional instructions here: Heroku Setup

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.