connect mementodb to telegram bot

66 views
Skip to first unread message

M Khanfar

unread,
Dec 17, 2023, 10:58:57 AM12/17/23
to mementodatabase
hi , i try to connect my memento database when i add new entry i want it appears in telegram bot , i try this code : but it seems not work . how i can find my library id ?? any help please 
import requests
import json
from telegram import Bot

MEMENTO_API_KEY = '<O4GAgxxxxxoHV1>'
TELEGRAM_BOT_TOKEN = '<686xxx483:AAEM8trwNQDB0TtcxxxdNq9Dw>'
CHAT_ID = '<5917xx756>'

def get_latest_entry():
    # Make a request to the Memento Database API to get the latest entry
    url = 'https://api.mementodatabase.com/api/entry/<YOUR_LIBRARY_ID>/entries'
    headers = {'Authorization': f'Bearer {MEMENTO_API_KEY}'}
    response = requests.get(url, headers=headers)
    data = response.json()

    # Extract the latest entry
    latest_entry = data[0]  # Assumes the entries are sorted by date, adjust as needed
    return latest_entry

def send_to_telegram(entry):
    # Send the entry information to your Telegram bot
    bot = Bot(token=TELEGRAM_BOT_TOKEN)
    message = f"New entry added:\n{json.dumps(entry, indent=2)}"
    bot.send_message(chat_id=CHAT_ID, text=message)

if __name__ == "__main__":
    # Get the latest entry from Memento Database
    latest_entry = get_latest_entry()

    # Send the latest entry to Telegram
    send_to_telegram(latest_entry)

M Khanfar

unread,
Dec 17, 2023, 12:39:11 PM12/17/23
to mementodatabase

i try this  too . but need my library id . how i got it ????                                           


import requests
import json
from telegram import Bot

MEMENTO_CLOUD_AUTH_TOKEN = 'O4xxxV1'
TELEGRAM_BOT_TOKEN = '6864x83:AAEM8txxNq9Dw'
CHAT_ID = '5xxx56'
YOUR_LIBRARY_ID = 'xxxxx'

def get_latest_entry():
    # Make a request to the Memento Cloud API to get the latest entry
    url = f'https://api.mementodatabase.com/api/entry/{YOUR_LIBRARY_ID}/entries?token={MEMENTO_CLOUD_AUTH_TOKEN}'
    response = requests.get(url)

    if response.status_code == 200:
        try:
            data = response.json()
            if data:
                latest_entry = data[0]
                return latest_entry
            else:
                print("No entries found.")
        except json.JSONDecodeError:
            print("Response is not in JSON format.")
    else:
        print(f"Error: {response.status_code}")

    return None

def send_to_telegram(entry):
    # Send the entry information to your Telegram bot
    bot = Bot(token=TELEGRAM_BOT_TOKEN)
    message = f"New entry added:\n{json.dumps(entry, indent=2)}"
    bot.send_message(chat_id=CHAT_ID, text=message)

if __name__ == "__main__":
    # Get the latest entry from Memento Cloud API
    latest_entry = get_latest_entry()

    if latest_entry:
        # Send the latest entry to Telegram
        send_to_telegram(latest_entry)

Reply all
Reply to author
Forward
0 new messages