telebotter / django-telegrambot

Simple app for Telegram bot in Django
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

Webhook does not appear to be set #17

Closed joshuakoh1 closed 3 years ago

joshuakoh1 commented 3 years ago

On start it seems to be setting the webhook URL. However, when sending messages to the bot, nothing gets posted to the webhook and pending updates keeps increasing.

Telegram Bot <BOT_NAME> setting webhook [ https://<URL>/users/telegram-webhook/<BOT_TOKEN>/ ] max connections:40 allowed updates:['ALL'] **pending updates:8** : True

When I manually access the webhook URL I can see that it's working as I get a {} response and I see an entry in the webserver logs. But I don't see anything if I send a message via Telegram and I do not see any line entry in the webserver logs at all as well.

settings.py

DJANGO_TELEGRAMBOT = {

    'MODE' : 'WEBHOOK', #(Optional [str]) # The default value is WEBHOOK,
                        # otherwise you may use 'POLLING'
                        # NB: if use polling you must provide to run
                        # a management command that starts a worker

    'WEBHOOK_SITE' : '<URL>',
    'WEBHOOK_PREFIX' : '/users/telegram-webhook/', # (Optional[str]) # If this value is specified,
                                  # a prefix is added to webhook url

    #'WEBHOOK_CERTIFICATE' : 'cert.pem', # If your site use self-signed
                         #certificate, must be set with location of your public key
                         #certificate.(More info at https://core.telegram.org/bots/self-signed )

    'STRICT_INIT': True, # If set to True, the server will fail to start if some of the
                         # apps contain telegrambot.py files that cannot be successfully
                         # imported.

    'DISABLE_SETUP': False, # If set to True, there will be no tries to set webhook or read
                            # updates from the telegram server on app's start
                            # (useful when developing on local machine; makes django's startup faster)

    'BOT_MODULE_NAME': 'telegrambot', #(Optional [str])  # The default name for file name containing telegram handlers which has to be placed inside your local app(s). Default is 'telegrambot'. Example is to put "telegrambot_handlers.py" file to local app's folder.

    'BOTS' : [
        {
           'ID': 'MainBot', # Unique identifier for your bot (used in your code only)

           'TOKEN': '<BOT_TOKEN>', # Your bots token (provided by botfather)

           'CONTEXT': True,  # Use context based handler functions (should be true for future versions)

           #'ALLOWED_UPDATES':(Optional[list[str]]), # List the types of
                                                   #updates you want your bot to receive. For example, specify
                                                   #``["message", "edited_channel_post", "callback_query"]`` to
                                                   #only receive updates of these types. See ``telegram.Update``
                                                   #for a complete list of available update types.
                                                   #Specify an empty list to receive all updates regardless of type
                                                   #(default). If not specified, the previous setting will be used.
                                                   #Please note that this parameter doesn't affect updates created
                                                   #before the call to the setWebhook, so unwanted updates may be
                                                   #received for a short period of time.

           #'TIMEOUT':(Optional[int|float]), # If this value is specified,
                                   #use it as the read timeout from the server

           #'WEBHOOK_MAX_CONNECTIONS':(Optional[int]), # Maximum allowed number of
                                   #simultaneous HTTPS connections to the webhook for update
                                   #delivery, 1-100. Defaults to 40. Use lower values to limit the
                                   #load on your bot's server, and higher values to increase your
                                   #bot's throughput.

           # 'MESSAGEQUEUE_ENABLED':(Optinal[bool]), # Make this True if you want to use messagequeue

           # 'MESSAGEQUEUE_ALL_BURST_LIMIT':(Optional[int]), # If not provided 29 is the default value

           # 'MESSAGEQUEUE_ALL_TIME_LIMIT_MS':(Optional[int]), # If not provided 1024 is the default value

           # 'MESSAGEQUEUE_REQUEST_CON_POOL_SIZE':(Optional[int]), # If not provided 8 is the default value

           #'POLL_INTERVAL' : (Optional[float]), # Time to wait between polling updates from Telegram in
                           #seconds. Default is 0.0

           #'POLL_CLEAN':(Optional[bool]), # Whether to clean any pending updates on Telegram servers before
                                   #actually starting to poll. Default is False.

           #'POLL_BOOTSTRAP_RETRIES':(Optional[int]), # Whether the bootstrapping phase of the `Updater`
                                   #will retry on failures on the Telegram server.
                                   #|   < 0 - retry indefinitely
                                   #|     0 - no retries (default)
                                   #|   > 0 - retry up to X times

           #'POLL_READ_LATENCY':(Optional[float|int]), # Grace time in seconds for receiving the reply from
                                   #server. Will be added to the `timeout` value and used as the read timeout from
                           #server (Default: 2).
        },
        # Other bots here with same structure.
    ],

}
joshuakoh1 commented 3 years ago

Further investigations revealed that it was a CloudFlare firewall that was blocking Telegram source IP