@require_setting('TELEGRAM_TOKEN')
@login_required
def add_telegram(request):
    (chat_id, chat_type, chat_name) = (None, None, None)
    qs = request.META['QUERY_STRING']
    if qs:
        try:
            (chat_id, chat_type, chat_name) = signing.loads(qs, max_age=600)
        except signing.BadSignature:
            return render(request, 'bad_link.html')
    if (request.method == 'POST'):
        project = _get_rw_project_for_user(request, request.POST.get('project'))
        channel = Channel(project=project, kind='telegram')
        channel.value = json.dumps({'id': chat_id, 'type': chat_type, 'name': chat_name})
        channel.save()
        channel.assign_all_checks()
        messages.success(request, 'The Telegram integration has been added!')
        return redirect('hc-channels', project.code)
    ctx = {'page': 'channels', 'projects': request.profile.projects(), 'chat_id': chat_id, 'chat_type': chat_type, 'chat_name': chat_name, 'bot_name': settings.TELEGRAM_BOT_NAME}
    return render(request, 'integrations/add_telegram.html', ctx)
@require_setting('TELEGRAM_TOKEN')
@login_required
def add_telegram(request):
    (chat_id, chat_type, chat_name) = (None, None, None)
    qs = request.META['QUERY_STRING']
    if qs:
        try:
            (chat_id, chat_type, chat_name) = signing.loads(qs, max_age=600)
        except signing.BadSignature:
            return render(request, 'bad_link.html')
    if (request.method == 'POST'):
        project = _get_rw_project_for_user(request, request.POST.get('project'))
        channel = Channel(project=project, kind='telegram')
        channel.value = json.dumps({'id': chat_id, 'type': chat_type, 'name': chat_name})
        channel.save()
        channel.assign_all_checks()
        messages.success(request, 'The Telegram integration has been added!')
        return redirect('hc-channels', project.code)
    ctx = {'page': 'channels', 'projects': request.profile.projects(), 'chat_id': chat_id, 'chat_type': chat_type, 'chat_name': chat_name, 'bot_name': settings.TELEGRAM_BOT_NAME}
    return render(request, 'integrations/add_telegram.html', ctx)