WhatsApp Integration in ERPNext using Server-Side Scripting

I’ve been attempting to integrate WhatsApp functionality into ERPNext using a server-side script. Specifically, I’m trying to send WhatsApp messages via the Askeva API within ERPNext’s server-side environment

I have written a server-side script to send WhatsApp messages using the Askeva API. The script seems correct, but when I execute it, I encounter a NameError: name '_print_' is not defined error.

script: def send_whatsapp_message(api_url, auth_token, message, recipient_number):
import urllib.parse
import urllib.request
import json

# Construct the payload
payload = {
    'method': 'SendMessage',
    'format': 'json',
    'v': '1.1',
    'auth_scheme': 'plain',
    'isTemplate': 'true',
    'msg_type': 'Text',
    'msg': message,
    'send_to': recipient_number,
    'Authorization': auth_token
}


data = urllib.parse.urlencode(payload).encode()

try:
    # Send GET request to Askeva API
    response = urllib.request.urlopen(api_url + '?' + data)
    
   
    if response.getcode() == 200:
        print('Message sent successfully.')
    else:
        print('Failed to send message. Status code:', response.getcode())
        print('Response:', response.read().decode())
except Exception as e:
    print('Error:', str(e))

Example usage

api_url = ‘https://app.askeva.in/api/rest/send_message
auth_token = ‘f68eb0dce6ab4797b0b65424adfe432780da2c8c9c7cf8e56556a5646f644797’
message = ‘Askeva is our WhatsApp-based Chatbot that can automate all kinds of business processes for a business in the World biggest platform WhatsApp.’
recipient_number = ‘+919988776655’

send_whatsapp_message(api_url, auth_token, message, recipient_number)

I’m seeking guidance on how to resolve this error and successfully integrate WhatsApp functionality into ERPNext using server-side scripting. Any insights, suggestions, or alternative approaches would be greatly appreciated.

Hello, Why don’t you create a separate app and put your custom code into it? Then try it. If you need any help, please let me know.

Thank you