Package: ba-whatsapp-api-client-python
ba-whatsapp-api-client-pythonДокументация на русском языкеPython library for intagration with WhatsAPP messanger via API ofbasis-api.comservice. To use the library you have to get a registration token and an account id in thepersonal area. There is a free developer account tariff plan.APIYou can find REST API documentation byurl. The library is a wrapper for REST API, so the documentation at the above url applies to the library as well.Installationpipinstallba-whatsapp-api-client-pythonImportfrom ba_whatsapp_api_client_python import APIAuthorizationTo send a message or to exacute some other Basis API method, you have to have the WhatsApp account in the phone application to be authorized. To authorize your account please go to thepersonal areaand scan a QR-code using the WhatsApp application.ExamplesHow to initialize an objectbasisAPI=API.BasisApi(ID_INSTANCE,API_TOKEN_INSTANCE)Sending a text message to a WhatsApp numberresult=basisAPI.sending.sendMessage('79001234567@g.us','Message text')Example url:sendTextMessage.pyPlease note that keys can be obtained from environment variables:fromosimportenvironID_INSTANCE=environ['ID_INSTANCE']API_TOKEN_INSTANCE=environ['API_TOKEN_INSTANCE']Sending an image via URLresult=basisAPI.sending.sendFileByUrl('120363025955348359@g.us','https://www.google.ru/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png','googlelogo_color_272x92dp.png','Google logo')Example url:sendPictureByLink.pySending an image by uploading from the diskresult=basisAPI.sending.sendFileByUpload('120363025955348359@g.us','C:\Games\PicFromDisk.png','PicFromDisk.png','Picture from disk')Example url:sendPictureByUpload.pyGroup creation and sending a message to the groupchatIds=["79001234567@c.us"]resultCreate=basisAPI.groups.createGroup('GroupName',chatIds)ifresultCreate.code==200:resultSend=basisAPI.sending.sendMessage(resultCreate.data['chatId'],'Message text')IMPORTANT: 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.Example url:createGroupAndSendMessage.pyReceive incoming messages by HTTP APIThe general concept of receiving data in the Basis API is describedhereTo start receiving messages by the HTTP API you need to execute the library method:basisAPI.webhooks.startReceivingNotifications(onEvent)onEvent - your method which should contain parameters:ParameterDescriptiontypewebhookreceived message type (string)bodymessage body (json)Message body types and formatshereThis method will be called when an incoming message is received. Next, process messages according to the business logic of your system.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.pyThe full list of the library methodsMethodDescriptionDocumentationaccount.getSettingsThe method is aimed for getting the current settings of the accountGetSettings.mdaccount.getStateInstanceThe method is aimed for getting the account stateGetStateInstance.mdaccount.getStatusInstanceThe method is aimed for getting the status of the account instance socket connection with WhatsAppGetStatusInstance.mdaccount.logoutThe method is aimed for logging out an accountLogout.mdaccount.qrThe method is aimed for getting QR codeQR.mdaccount.rebootThe method is aimed for rebooting an accountReboot.mdaccount.setProfilePictureThe method is aimed for setting an account pictureSetProfilePicture.mdaccount.setSettingsThe method is aimed for setting an account settingsSetSettings.mdaccount.setSystemProxyThe method is aimed for setting a system proxy. Use the method when you need to reset custom proxy settings to system onesSetSystemProxy.mdgroups.addGroupParticipantМетод добавляет участника в групповой чатAddGroupParticipant.mdgroups.createGroupThe method adds a participant to a group chat. IMPORTANT: If one tries to create a group with a non-existent number, WhatsApp may block the sender's number.CreateGroup.mdgroups.getGroupDataThe method gets group chat dataGetGroupData.mdgroups.leaveGroupThe method makes the current account user leave the group chatLeaveGroup.mdgroups.removeAdminhe method removes a participant from group chat administration rightsRemoveAdmin.mdgroups.removeGroupParticipantThe method removes a participant from a group chatRemoveGroupParticipant.mdgroups.setGroupAdminThe method sets a group chat participant as an administratorSetGroupAdmin.mdgroups.setGroupPictureThe method sets a group pictureSetGroupPicture.mdgroups.updateGroupNameThe method changes a group chat nameUpdateGroupName.mdjournals.getChatHistoryThe method returns the chat message historyGetChatHistory.mdjournals.lastIncomingMessagesThe method returns the last incoming messages of the account. In the default mode the incoming messages for 24 hours are returnedGetChatHistory.mdjournals.lastOutgoingMessagesThe method returns the last outgoing messages of the account. In the default mode the last messages for 24 hours are returnedLastOutgoingMessages.mdmarking.readChatThe method is aimed for marking messages in a chat as read. Either all messages or a specified message in a chat can be marked as readReadChat.mddevice.getDeviceInfoThe method is aimed for getting information about the device (phone) running WhatsApp Business applicationGetDeviceInfo.mdqueues.clearMessagesQueueThe method is aimed for clearing the queue of messages to be sentClearMessagesQueue.mdqueues.showMessagesQueueThe method is aimed for getting a list of messages in the queue to be sentShowMessagesQueue.mdreceiving.deleteNotificationThe method is aimed for deleting an incoming notification from the notification queueDeleteNotification.mdreceiving.receiveNotificationThe method is aimed for receiving one incoming notification from the notifications queueReceiveNotification.mdsending.sendButtonsThe method is aimed for sending a button message to a personal or a group chatSendButtons.mdsending.sendContactThe method is aimed for sending a contact messageSendContact.mdsending.sendFileByUploadThe method is aimed for sending a file uploaded by formSendFileByUpload.mdsending.sendFileByUrlThe method is aimed for sending a file uploaded by UrlSendFileByUrl.mdsending.sendLinkThe method is aimed for sending a message with a link, by which an image preview, title and description will be addedSendLink.mdsending.sendListMessageThe method is aimed for sending a message with a select button from a list of values to a personal or a group chatSendListMessage.mdsending.sendLocationThe method is aimed for sending a location messageSendLocation.mdsending.sendMessageThe method is aimed for sending a text message to a personal or a group chatSendMessage.mdsending.sendTemplateButtonsThe method is aimed for sending a message with template list interactive buttons to a personal or a group chatSendTemplateButtons.mdsending.forwardMessagesThe method is intended for forwarding messages to a personal or group chatForwardMessages.mdserviceMethods.checkWhatsappThe method checks WhatsApp account availability on a phone numberCheckWhatsapp.mdserviceMethods.getAvatarThe method returns a user or a group chat avatarGetAvatar.mdserviceMethods.getContactInfoThe method is aimed for getting information on a contactGetContactInfo.mdserviceMethods.getContactsThe method is aimed for getting a list of the current account contactsGetContacts.mdserviceMethods.setDisappearingChatThe method is aimed for changing settings of disappearing messages in chats. The standard settings of the application are to be used: 0 (off), 86400 (24 hours), 604800 (7 days), 7776000 (90 days)SetDisappearingChat.mdserviceMethods.archiveChatThe method archives a chat. One can archive chats that have at least one incoming messageArchiveChat.mdserviceMethods.deleteMessageThe method deletes a message from a chatDeleteMessage.mdserviceMethods.unarchiveChatThe method unarchives a chatUnarchiveChat.mdserviceMethods.setDisappearingChatThe method is aimed for changing settings of disappearing messages in chatsSetDisappearingChat.mdwebhooks.startReceivingNotificationsThe method is aimed for starting to receive webhookswebhooks.stopReceivingNotificationsThe method is aimed for stopping to receive webhooksService methods documentationhttps://en-cabinet.basis-api.com/docs/en/api/External productsrequests- for http requestsLicenseLicensed under MIT terms. Please see fileLICENSE