Skip to content

Instantly share code, notes, and snippets.

@jamesperes-zz
Created November 6, 2017 11:28
Show Gist options
  • Save jamesperes-zz/a44f76b0913cce7ec7c3fd1a8497904c to your computer and use it in GitHub Desktop.
Save jamesperes-zz/a44f76b0913cce7ec7c3fd1a8497904c to your computer and use it in GitHub Desktop.
from django.shortcuts import render
import telepot
from django.http import HttpResponseRedirect
from .models import *
bot = telepot.Bot('TOKEN HERE!!')
def page_send(request):
if request.method == 'GET':
user_located = UserTelegram.objects.all()
return render(request, 'bot/index.html', {'users': user_located})
elif request.method == 'POST':
post_file = request.FILES.get('post_file')
if post_file:
user_post = request.POST.get('user')
extension = post_file.name[post_file.name.rfind('.'):]
if extension in ('.jpg', '.png', '.jpeg', '.gif'):
bot.sendPhoto(user_post, post_file)
else:
bot.sendDocument(user_post, post_file)
message = request.POST.get('message')
if message:
user_post = request.POST.get('user')
bot.sendMessage(user_post, message)
return HttpResponseRedirect('/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment