Skip to content

Commit

Permalink
add some simple operations
Browse files Browse the repository at this point in the history
  • Loading branch information
madanalogy committed Nov 13, 2023
1 parent 65151e8 commit 666fed2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions actions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
def run_add(chat_id, text):
return text
import firebase_admin
from firebase_admin import firestore

# Application Default credentials are automatically created.
app = firebase_admin.initialize_app()
db = firestore.client()


async def run_add(chat_id, text):
trans_db = db.collection("chats").document(chat_id).collection("transactions")
update_time, trans_ref = await trans_db.add(text)
return f"{trans_ref.id} created on {update_time}"


def run_list(chat_id, text):
return text
trans_db = db.collection("chats").document(chat_id).collection("transactions")
docs = trans_db.stream()

output = ""
for doc in docs:
output += f"{doc.id} => {doc.to_dict()}"
return output


def run_detail(chat_id, text):
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ async def process(request):
bot = telegram.Bot(token=BOT_TOKEN)
update = telegram.Update.de_json(request.get_json(force=True), bot)
chat_id = update.message.chat.id
response = get_response(chat_id, update.message.text)
response = await get_response(chat_id, update.message.text)
await bot.sendMessage(chat_id=chat_id, text=response)


def get_response(chat_id, text):
async def get_response(chat_id, text):
if text.startswith("/start"):
return constants.INTRO
if text.startswith("/add"):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ python-dotenv~=1.0.0
asyncio~=3.4.3
python-telegram-bot
functions_framework
firebase-admin

0 comments on commit 666fed2

Please sign in to comment.