Package: whatsapp-api-client-python
whatsapp-api-client-pythonДокументация на русском языке.whatsapp-api-client-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.Installationpython-mpipinstallwhatsapp-api-client-pythonImportfrom whatsapp_api_client_python import APIExamplesHow to initialize an objectgreenAPI = API.GreenAPI(
    "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)Sending a text message to a WhatsApp numberLink to example:sendTextMessage.py.response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text")

print(response.data)Sending an image via URLLink to example:sendPictureByLink.py.response = greenAPI.sending.sendFileByUrl(
    "11001234567@c.us",
    "https://download.samplelib.com/png/sample-clouds2-400x300.png",
    "sample-clouds2-400x300.png",
    "Sample PNG"
)

print(response.data)Sending an image by uploading from the diskLink to example:sendPictureByUpload.py.response = greenAPI.sending.sendFileByUpload(
    "11001234567@c.us",
    "data/rates.png",
    "rates.png",
    "Available rates"
)

print(response.data)Group creation and sending a message to the groupAttention. If one tries to create a group with a non-existent number, WhatsApp may block the sender's number. The
number in the example is non-existent.Link to example:createGroupAndSendMessage.py.create_group_response = greenAPI.groups.createGroup(
    "Group Name", ["11001234567@c.us"]
)
if create_group_response.code == 200:
    send_message_response = greenAPI.sending.sendMessage(
        create_group_response.data["chatId"], "Message text"
    )Receive incoming messages by HTTP APILink to example:receiveNotification.py.The general concept of receiving data in the GREEN API is describedhere. To start receiving notifications by the HTTP API you need to execute the library method:greenAPI.webhooks.startReceivingNotifications(onEvent)onEvent - your function which should contain parameters:ParameterDescriptiontypeWebhookreceived notification type (str)bodynotification body (dict)Notification body types and formats can be foundhere.This method will be called when an incoming notification is received. Next, process notifications according to the
business logic of your system.Sending a polling messageLink to example:sendPoll.py.response = greenAPI.sending.sendPoll(
    "11001234567@c.us",
    "Please choose a color:",
    [
        {"optionName": "Red"},
        {"optionName": "Green"},
        {"optionName": "Blue"}
    ]
)

print(response.data)Examples listDescriptionModuleExample of sending textsendTextMessage.pyExample of sending a picture by URLsendPictureByLink.pyExample of sending a picture by uploading from the disksendPictureByUpload.pyExample of a group creation and sending a message to the groupcreateGroupAndSendMessage.pyExample of incoming webhooks receivingreceiveNotification.pyExample of sending a polling messagesendPoll.pyThe full list of the library methodsAPI methodDescriptionDocumentation linkaccount.getSettingsThe method is designed to get the current settings of the accountGetSettingsaccount.getWaSettingsThe method is designed to get information about the WhatsApp accountGetWaSettingsaccount.setSettingsThe method is designed to set the account settingsSetSettingsaccount.getStateInstanceThe method is designed to get the state of the accountGetStateInstanceaccount.getStatusInstanceThe method is designed to get the socket connection state of the account instance with WhatsAppGetStatusInstanceaccount.rebootThe method is designed to restart the accountRebootaccount.logoutThe method is designed to unlogin the accountLogoutaccount.qrThe method is designed to get a QR codeQRaccount.setProfilePictureThe method is designed to set the avatar of the accountSetProfilePictureaccount.getAuthorizationCodeThe method is designed to authorize an instance by phone numberGetAuthorizationCodedevice.getDeviceInfoThe method is designed to get information about the device (phone) on which the WhatsApp Business application is runningGetDeviceInfogroups.createGroupThe method is designed to create a group chatCreateGroupgroups.updateGroupNameThe method changes the name of the group chatUpdateGroupNamegroups.getGroupDataThe method gets group chat dataGetGroupDatagroups.addGroupParticipantThe method adds a participant to the group chatAddGroupParticipantgroups.removeGroupParticipantThe method removes the participant from the group chatRemoveGroupParticipantgroups.setGroupAdminThe method designates a member of a group chat as an administratorSetGroupAdmingroups.removeAdminThe method deprives the participant of group chat administration rightsRemoveAdmingroups.setGroupPictureThe method sets the avatar of the groupSetGroupPicturegroups.leaveGroupThe method logs the user of the current account out of the group chatLeaveGroupjournals.getChatHistoryThe method returns the chat message historyGetChatHistoryjournals.getMessageThe method returns a chat messageGetMessagejournals.lastIncomingMessagesThe method returns the most recent incoming messages of the accountLastIncomingMessagesjournals.lastOutgoingMessagesThe method returns the last sent messages of the accountLastOutgoingMessagesqueues.showMessagesQueueThe method is designed to get the list of messages that are in the queue to be sentShowMessagesQueuequeues.clearMessagesQueueThe method is designed to clear the queue of messages to be sentClearMessagesQueuemarking.readChatThe method is designed to mark chat messages as readReadChatreceiving.receiveNotificationThe method is designed to receive a single incoming notification from the notification queueReceiveNotificationreceiving.deleteNotificationThe method is designed to remove an incoming notification from the notification queueDeleteNotificationreceiving.downloadFileThe method is for downloading received and sent filesDownloadFilesending.sendMessageThe method is designed to send a text message to a personal or group chatSendMessagesending.sendButtonsThe method is designed to send a message with buttons to a personal or group chatSendButtonssending.sendTemplateButtonsThe method is designed to send a message with interactive buttons from the list of templates in a personal or group chatSendTemplateButtonssending.sendListMessageThe method is designed to send a message with a selection button from a list of values to a personal or group chatSendListMessagesending.sendFileByUploadThe method is designed to send a file loaded through a form (form-data)SendFileByUploadsending.sendFileByUrlThe method is designed to send a file downloaded via a linkSendFileByUrlsending.uploadFileThe method is designed to upload a file to the cloud storage, which can be sent using the sendFileByUrl methodUploadFilesending.sendLocationThe method is designed to send a geolocation messageSendLocationsending.sendContactThe method is for sending a message with a contactSendContactsending.sendLinkThe method is designed to send a message with a link that will add an image preview, title and descriptionSendLinksending.forwardMessagesThe method is designed for forwarding messages to a personal or group chatForwardMessagessending.sendPollThe method is designed for sending messages with a poll to a private or group chatSendPollserviceMethods.checkWhatsappThe method checks if there is a WhatsApp account on the phone numberCheckWhatsappserviceMethods.getAvatarThe method returns the avatar of the correspondent or group chatGetAvatarserviceMethods.getContactsThe method is designed to get a list of contacts of the current accountGetContactsserviceMethods.getContactInfoThe method is designed to obtain information about the contactGetContactInfoserviceMethods.deleteMessageThe method deletes the message from chatDeleteMessageserviceMethods.archiveChatThe method archives the chatArchiveChatserviceMethods.unarchiveChatThe method unarchives the chatUnarchiveChatserviceMethods.setDisappearingChatThe method is designed to change the settings of disappearing messages in chatsSetDisappearingChatwebhooks.startReceivingNotificationsThe method is designed to start receiving new notificationswebhooks.stopReceivingNotificationsThe method is designed to stop receiving new notificationsService methods documentationhttps://green-api.com/en/docs/api/.External productsrequests- for HTTP requests.LicenseLicensed underCreative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)terms.
Please see fileLICENSE.