Commit b872ff1c authored by Ale's avatar Ale

fix: Fix indentation in connector views

parent 943ec773
# python
import json
import requests
# django
from django.shortcuts import render
from django.views import View
from django.http import JsonResponse
# project
from django.conf import settings
# python
import json
import requests
# django
from django.shortcuts import render
from django.views import View
from django.http import JsonResponse
# project
from django.conf import settings
# Create your views here.
class TelegramWebhookView(View):
def get(self, request, *args, **kwargs):
return JsonResponse({"ko": "Rasklat!"})
def get(self, request, *args, **kwargs):
return JsonResponse({"ko": "Rasklat!"})
def post(self, request, *args, **kwargs):
try:
data = json.loads(request.body)
message = data["message"]
chat = message["chat"]
self.send_message(
"Gracias",
chat["id"]
)
except Exception as e:
return JsonResponse({
"ko" : "Bad Request"
})
return JsonResponse({
"ok": "Succesful request"
})
@staticmethod
def send_message(message, chat_id):
data = {
"chat_id" : chat_id,
"text" : message,
"parse_mode" : "Markdown",
}
def post(self, request, *args, **kwargs):
try:
response = requests.post(
"%s%s/sendMessage" % (
"https://api.telegram.org/bot",
TELEGRAM_BOT_TOKEN
), data=data
data = json.loads(request.body)
message = data["message"]
chat = message["chat"]
self.send_message(
"Gracias",
chat["id"]
)
except Exception as e:
return JsonResponse({
"ko" : "There was a problem connecting to Telegram API"
"ko" : "Bad Request"
})
return JsonResponse({
"ok": "Succesful request"
})
@staticmethod
def send_message(message, chat_id):
data = {
"chat_id" : chat_id,
"text" : message,
"parse_mode" : "Markdown",
}
try:
response = requests.post(
"%s%s/sendMessage" % (
"https://api.telegram.org/bot",
TELEGRAM_BOT_TOKEN
), data=data
)
except Exception as e:
return JsonResponse({
"ko" : "There was a problem connecting to Telegram API"
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment