Package: whatsapp-api-webhook-server-python
whatsapp-api-webhook-server-pythonДокументация на русском языке.whatsapp-api-webhook-server-python is a library for integration with WhatsApp messenger using the API
servicegreen-api.com. You should get a registration token and an account ID in
yourpersonal cabinetto use the library. There is a free developer account tariff.APIThe documentation for the REST API can be found at thelink. The library is a wrapper
for the REST API, so the documentation at the link above also applies.AuthorizationTo send a message or perform other Green API methods, the WhatsApp account in the phone app must be authorized. To
authorize the account, go to yourcabinetand scan the QR code using the WhatsApp app.Examples of preparing the environmentExample of preparing the environment for Ubuntu ServerUpdating the systemUpdate the system:sudoaptupdate
sudoaptupgrade-yFirewallSet up the firewall:Allow the SSH connection:sudoufwallowsshBase rules:sudoufwdefaultdenyincoming
sudoufwdefaultallowoutgoingAllow HTTP and HTTPS connections:sudoufwallowhttp
sudoufwallowhttpsEnable the firewall:sudoufwenableInstallationA package management system must be installed:sudoaptinstallpython3-pipLibrary installation:python3-mpipinstallwhatsapp-api-webhook-server-pythonAs an example you can download and runour script. The script sends all incoming notifications.wgethttps://raw.githubusercontent.com/green-api/whatsapp-api-webhook-server-python/master/examples/echo.pypython3-mecho.pyExample of preparing the environment for Windows ServerPython installationPython must be installed on the server.Python installation instructions.Как настроить конфигурацию веб-сервераTo use IIS (Internet Information Services) as a web server, you need to configure the configuration fileweb.configso
that the IIS service can properly execute Python code. This file is located in the publication folder of your web
server.After installing the interpreter, you should define the HttpPlatform handler in theweb.configfile. This handler will
transfer connections to the standalone Python process.Example configuration file:<?xml version="1.0" encoding="utf-8"?><configuration><system.webServer><handlers><addname="PythonHandler"path="*"verb="*"modules="httpPlatformHandler"resourceType="Unspecified"/></handlers><httpPlatformarguments="<Path-to-server-file>\echo.py"processesPerApplication="16"processPath="<Path-to-python>\python.exe"startupTimeLimit="60"stdoutLogEnabled="true"stdoutLogFile="<Path-to-log-file>\python.log"><environmentVariables><environmentVariablename="SOME_VARIABLE"value="%SOME_VAR%"/></environmentVariables></httpPlatform></system.webServer></configuration><Path-to-python>- the path to the executable file of the Python interpreter;<Path-to-server-file>- the path to the server executable file (e.g. echo.py from the example);<Path-to-log-file>- the path to the log file.You will also need to open the corresponding port to the external network by setting the firewall settings (Advanced
Options -> Rules for incoming connections -> Create Rule -> Rule Type = Port Protocols, Port -> TCP, specify the
firewall settings. options -> Rules for incoming connections -> Create Rule -> Rule Type = Port, Protocols and Port ->
TCP, specify port, Action -> Allow connection).An example of deploying a server environment using DockerThe machine should have Docker installed.To get an image from the Docker Hub, you need to write a command:sudo docker pull greenapi/whatsapp-api-webhook-server-pythonRun the image in a container with the port and the console displayed:sudo docker run --publish 8080:80 -it greenapi/whatsapp-api-webhook-server-pythonYou can specify any free machine port instead of port 8080. Inpersonal cabinetyou
will need to specify the IP (or external machine name) with this port.After starting the container, the container console should receive incoming notifications.Running the serverTo use in your solutions, simply import the webhooksHandler class.import whatsapp_api_webhook_server_python.webhooksHandler as webhooksHandlerStart of the server:webhooksHandler.startServer('127.0.0.1', 80, onEvent)TheonEventparameter is a handler function that should be created by the developer.Method parameters:ParameterDescriptionwebhooksHandlerlibrary class instancetypeWebhooktype of incoming notificationbodynotification bodyExample:echo.py.How to reroute incoming notifications to a web serverTo reroute incoming notifications, you need to set the notification sending address (URL)
inpersonal cabinet.Service methods documentationService methods documentationLicenseLicensed underCreative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)terms.
Please see fileLICENSE.