Skip to content

WEBHOOK doesn't work! #8

@mbnoimi

Description

@mbnoimi

Hi,

My project works fine in case I set POLLING while is doesn't work at all with WEBHOOK. I suspect I missed smoothing in settings.py but I couldn't figure it out.

May I get some help please?

NOTES:

  1. I'm still newbie in both django and django-telegrambot so forgive me for the silly questions.
  2. My project root is https://mydomain.com/api/
  3. As you can see I use REST framework which works fine in https://mydomain.com/api/
  4. I couldn't know where can I catch the errors regarding WEBHOOK but Apache always identify error Old Handler API is deprecated #6 as [wsgi:error]
  5. I successfully generated mydomain-crt.pem using win-acme for Let's Encrypt; It works fine for django in general but I'm not sure about it for django-telegrambot
  6. I'm able to access https://mydomain.com/api/admin/django-telegrambot/ and see:
    image

settings.py

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxx'
DEBUG = False # NOTE: Dev mode

ALLOWED_HOSTS = [
    '.mydomain.com',
    '.mydomain.com.',
    '.mydomain.com',
    '.mydomain.com.',
]

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'django_telegrambot',
    'api',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'somebot.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'somebot.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# TODO: Internationalization
LANGUAGE_CODE = 'en'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "static")

DJANGO_TELEGRAMBOT = {
# FIXME: Bot dosn't response in Webhook mode 
    'MODE' : 'WEBHOOK', # (Optional [str]) 
    'WEBHOOK_SITE' : 'https://mydomain.com',
    'WEBHOOK_PREFIX' : '/api/',  
    'WEBHOOK_CERTIFICATE' : 'C:/apache-certs/mydomain-crt.pem', 

    'BOTS' : [
        {
           'TOKEN': '1234567890:xxxxxxxxxxxxxxxxx',
        },
    ],

}

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ]
}

MEDIA_URL = '/uploads/'
MEDIA_ROOT = os.path.join(BASE_DIR, "uploads")

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions