Skip to content

Commit

Permalink
Merge pull request #2496 from tkalir/feature-2494-change-telegram-bot…
Browse files Browse the repository at this point in the history
…-to-use-webhook

adding telegram endpoint for webhook and table for tracking forwarded…
  • Loading branch information
tkalir authored Dec 6, 2023
2 parents 76abf30 + 6b4bd59 commit a263185
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
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 ###
8 changes: 8 additions & 0 deletions anyway/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,14 @@ def embedded_reports_api():
return response


@app.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)


# User system API
app.add_url_rule("/user/add_role", view_func=add_role, methods=["POST"])
app.add_url_rule(
Expand Down
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 a263185

Please sign in to comment.