I want to build a new whatsapp utility app in django

47 views Asked by At

I'm new in django, want to build a whatsapp utility app , which can use API endpoints provided by the API provider to send text and media files. functionality should be like.

  1. Create a Instance ID using access token(provided by the API provider)
  2. Generate a qr_code : with the help of created instance ID and known access token.
  3. Scan generated qr_code to login to whatsapp web and send the text and media files using API endpoints provided the API provider.

Any help would be appreciated.

I wrote a views.py file:

`

from django.http import HttpResponseimport requestsfrom django.views.decorators.csrf import csrf_exemptfrom django.http import JsonResponseWAPI_URL="https://wapicloud.in/"@csrf_exemptdef whatsapp_create_instance(request):if request.method == 'POST':api_provider = request.POST.get('api_provider', '')phone_number = request.POST.get('phone_number', '')access_token = request.POST.get('token', '')

if api_provider == '' or api_provider == '1':
    url = WAPI_URL + 'api/create_instance?access_token=' + access_token

response = hit_curl_get(url)
response_data = {}

# 2nd API
if response\['status'\] == "success":\`your text\`
    instance_id = response\['instance_id'\]
    url_qr = WAPI_URL + 'api/get_qrcode?instance_id=' + instance_id + '&access_token=' + access_token
    response_qr = hit_curl_get(url_qr)

    # 3rd API
    if response_qr\['status'\] == "success":
        hookurl = "https://webhook.site/XXXXXXXX.com/web/123"
        enable = "true"
        url_webhook = WAPI_URL + 'api/set_webhook?webhook_url=' + hookurl + '&enable=' + enable + '&instance_id=' + instance_id + '&access_token=' + access_token
        response_webhook = hit_curl_get(url_webhook)

        response_data\['webhook_status'\] = response_webhook\['status'\]
        response_data\['webhook_message'\] = response_webhook\['message'\]

response_data\['instance_status'\] = response\['status'\]
response_data\['instance_id'\] = response\['instance_id'\]
response_data\['instance_message'\] = response\['message'\]

response_data\['qr_status'\] = response_qr\['status'\]
response_data\['qr_message'\] = response_qr\['message'\]
response_data\['base64'\] = response_qr.get('base64', '')

return JsonResponse(response_data)

return HttpResponse("Invalid Request")

def hit_curl_get(url):# Assuming you have a function or library to handle HTTP requests, like the requests libraryresponse = requests.get(url)return response.json() # Assuming the response is in JSON format`

but after run the above whatsapp_create_instance api endpoint in POSTMAN getting an Internal server error

0

There are 0 answers