Socket
Socket
Sign inDemoInstall

basic-api-client-python

Package Overview
Dependencies
1
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    basic-api-client-python

This library helps you easily create a python ' 'application to connect the WhatsApp API using service api.basis-api.com


Maintainers
1

Readme

basic-api-client-python

Python application Upload Python Package

Python library for intagration with WhatsAPP messanger via API of api.basis-api.com service. To use the library you have to get a registration token and an account id in the personal area. There is a free developer account tariff plan.

API

You can find REST API documentation by url. The library is a wrapper for REST API, so the documentation at the above url applies to the library as well.

Installation

pip install basic-api-client-python

Import

from basic_api_client_python import API

Authorization

To send a message or to exacute some other Basic-API method, you have to have the WhatsApp account in the phone application to be authorized. To authorize your account please go to the personal area and scan a QR-code using the WhatsApp application.

Examples

How to initialize an object

basicAPI = API.BasicApi(ID_INSTANCE, API_TOKEN_INSTANCE)

Sending a text message to a WhatsApp number

result = basicAPI.sending.sendMessage('79001234567@g.us', 'Message text')

Example url: sendTextMessage.py

Please note that keys can be obtained from environment variables:

from os import environ

ID_INSTANCE = environ['ID_INSTANCE']
API_TOKEN_INSTANCE = environ['API_TOKEN_INSTANCE']

Sending an image via URL

result = basicAPI.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.py

Sending an image by uploading from the disk

result = basicAPI.sending.sendFileByUpload('120363025955348359@g.us', 
        'C:\Games\PicFromDisk.png', 
        'PicFromDisk.png', 'Picture from disk')

Example url: sendPictureByUpload.py

Group creation and sending a message to the group

chatIds = [
    "79001234567@c.us"
]
resultCreate = basicAPI.groups.createGroup('GroupName', 
    chatIds)

if resultCreate.code == 200:
    resultSend = basicAPI.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.py

Receive incoming messages by HTTP API

The general concept of receiving data in the Basic API is described here To start receiving messages by the HTTP API you need to execute the library method:

basicAPI.webhooks.startReceivingNotifications(onEvent)

onEvent - your method which should contain parameters:

ParameterDescription
typewebhookreceived message type (string)
bodymessage body (json)

Message body types and formats here

This method will be called when an incoming message is received. Next, process messages according to the business logic of your system.

Examples list

DescriptionModule
Example of sending textsendTextMessage.py
Example of sending a picture by URLsendPictureByLink.py
Example of sending a picture by uploading from the disksendPictureByUpload.py
Example of a group creation and sending a message to the groupcreateGroupAndSendMessage.py
Example of incoming webhooks receivingreceiveNotification.py

The full list of the library methods

MethodDescriptionDocumentation
account.getSettingsThe method is aimed for getting the current settings of the accountGetSettings.md
account.getStateInstanceThe method is aimed for getting the account stateGetStateInstance.md
account.getStatusInstanceThe method is aimed for getting the status of the account instance socket connection with WhatsAppGetStatusInstance.md
account.logoutThe method is aimed for logging out an accountLogout.md
account.qrThe method is aimed for getting QR codeQR.md
account.rebootThe method is aimed for rebooting an accountReboot.md
account.setProfilePictureThe method is aimed for setting an account pictureSetProfilePicture.md
account.setSettingsThe method is aimed for setting an account settingsSetSettings.md
account.setSystemProxyThe method is aimed for setting a system proxy. Use the method when you need to reset custom proxy settings to system onesSetSystemProxy.md
groups.addGroupParticipantМетод добавляет участника в групповой чатAddGroupParticipant.md
groups.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.md
groups.getGroupDataThe method gets group chat dataGetGroupData.md
groups.leaveGroupThe method makes the current account user leave the group chatLeaveGroup.md
groups.removeAdminhe method removes a participant from group chat administration rightsRemoveAdmin.md
groups.removeGroupParticipantThe method removes a participant from a group chatRemoveGroupParticipant.md
groups.setGroupAdminThe method sets a group chat participant as an administratorSetGroupAdmin.md
groups.setGroupPictureThe method sets a group pictureSetGroupPicture.md
groups.updateGroupNameThe method changes a group chat nameUpdateGroupName.md
journals.getChatHistoryThe method returns the chat message historyGetChatHistory.md
journals.lastIncomingMessagesThe method returns the last incoming messages of the account. In the default mode the incoming messages for 24 hours are returnedGetChatHistory.md
journals.lastOutgoingMessagesThe method returns the last outgoing messages of the account. In the default mode the last messages for 24 hours are returnedLastOutgoingMessages.md
marking.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.md
device.getDeviceInfoThe method is aimed for getting information about the device (phone) running WhatsApp Business applicationGetDeviceInfo.md
queues.clearMessagesQueueThe method is aimed for clearing the queue of messages to be sentClearMessagesQueue.md
queues.showMessagesQueueThe method is aimed for getting a list of messages in the queue to be sentShowMessagesQueue.md
receiving.deleteNotificationThe method is aimed for deleting an incoming notification from the notification queueDeleteNotification.md
receiving.receiveNotificationThe method is aimed for receiving one incoming notification from the notifications queueReceiveNotification.md
sending.sendButtonsThe method is aimed for sending a button message to a personal or a group chatSendButtons.md
sending.sendContactThe method is aimed for sending a contact messageSendContact.md
sending.sendFileByUploadThe method is aimed for sending a file uploaded by formSendFileByUpload.md
sending.sendFileByUrlThe method is aimed for sending a file uploaded by UrlSendFileByUrl.md
sending.sendLinkThe method is aimed for sending a message with a link, by which an image preview, title and description will be addedSendLink.md
sending.sendListMessageThe method is aimed for sending a message with a select button from a list of values to a personal or a group chatSendListMessage.md
sending.sendLocationThe method is aimed for sending a location messageSendLocation.md
sending.sendMessageThe method is aimed for sending a text message to a personal or a group chatSendMessage.md
sending.sendTemplateButtonsThe method is aimed for sending a message with template list interactive buttons to a personal or a group chatSendTemplateButtons.md
sending.forwardMessagesThe method is intended for forwarding messages to a personal or group chatForwardMessages.md
serviceMethods.checkWhatsappThe method checks WhatsApp account availability on a phone numberCheckWhatsapp.md
serviceMethods.getAvatarThe method returns a user or a group chat avatarGetAvatar.md
serviceMethods.getContactInfoThe method is aimed for getting information on a contactGetContactInfo.md
serviceMethods.getContactsThe method is aimed for getting a list of the current account contactsGetContacts.md
serviceMethods.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.md
serviceMethods.archiveChatThe method archives a chat. One can archive chats that have at least one incoming messageArchiveChat.md
serviceMethods.deleteMessageThe method deletes a message from a chatDeleteMessage.md
serviceMethods.unarchiveChatThe method unarchives a chatUnarchiveChat.md
serviceMethods.setDisappearingChatThe method is aimed for changing settings of disappearing messages in chatsSetDisappearingChat.md
webhooks.startReceivingNotificationsThe method is aimed for starting to receive webhooks
webhooks.stopReceivingNotificationsThe method is aimed for stopping to receive webhooks

Service methods documentation

https://api.basis-api.com/en/docs/api/

External products

License

Licensed under MIT terms. Please see file LICENSE

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc