Skip to content

Commit

Permalink
adding telegram endpoint for webhook and table for tracking forwarded…
Browse files Browse the repository at this point in the history
… messages
  • Loading branch information
tkalir committed Dec 6, 2023
1 parent d749600 commit 4a6a25f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
32 changes: 32 additions & 0 deletions alembic/versions/881e7b1dba8a_track_telegram_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""track telegram messages
Revision ID: 881e7b1dba8a
Revises: 664f8a93794e
Create Date: 2023-11-21 12:39:32.931262
"""

# revision identifiers, used by Alembic.
revision = '881e7b1dba8a'
down_revision = '664f8a93794e'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('telegram_forwarded_messages',
sa.Column('message_id', sa.String(), nullable=True),
sa.Column('newsflash_id', sa.Integer(), nullable=False),
sa.Column('group_sent', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('message_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('telegram_forwarded_messages')
# ### end Alembic commands ###
9 changes: 8 additions & 1 deletion anyway/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,4 +1504,11 @@ class DownloadData(Resource):
@api.expect(parser)
def get(self):
args = download_data_parser.parse_args()
return get_downloaded_data(args.get('format', 'csv'), args.get('years_ago', DEFAULT_NUMBER_OF_YEARS_AGO))
return get_downloaded_data(args.get('format', 'csv'), args.get('years_ago', DEFAULT_NUMBER_OF_YEARS_AGO))

@api.route("/api/telegram/webhook", methods=["POST"])
def telegram_webhook():
update = request.json # Telegram sends updates in JSON format
logging.info(f"Received Telegram update: {update}")

return jsonify(success=True)
6 changes: 6 additions & 0 deletions anyway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2975,3 +2975,9 @@ class TelegramGroups(TelegramGroupsBase):

class TelegramGroupsTest(TelegramGroupsBase):
__tablename__ = "telegram_groups_test"

class TelegramForwardedMessages():
__tablename__ = 'telegram_forwarded_messages'
message_id = Column(String(), primary_key=True)
newsflash_id = Column(BigInteger(), nullable=False)
group_sent = Column(String(), nullable=False),

0 comments on commit 4a6a25f

Please sign in to comment.