Chat identifier#
The chat identifier (chatId) is a unique marker required to correctly send messages through GREEN-API. It can belong to either a person or a group. In the case of a group chat, the chat identifier may contain a minus sign "-".
chatId format
- Personal chat:
"10000000"(a positive number) - Group:
"-10000000000000"(always starts with a minus)
How to get a chat identifier?#
You can get a chat identifier:
-
When processing incoming notifications
The chat identifier will be specified in the "sender" field of the
senderDataobject
Notification example:{ "typeWebhook": "incomingMessageReceived", "instanceData": { "idInstance": 4100000000, "wid": "79876543210@c.us", "typeInstance": "telegram" }, "timestamp": 1588091580, "idMessage": "1769676078000", "senderData": { "chatId": "10000000", "chatType": "user", "sender": "10000000", "chatName": "Vasilisa the Wise", "senderName": "Vasilisa the Wise", "senderType": "user", "senderContactName": "Vasilisa the Wise", "senderPhoneNumber": 79876543210 }, "messageData": { "typeMessage": "textMessage", "textMessageData": { "textMessage": "I use GREEN-API to send this message!" } } } -
Through the incoming messages journal LastIncomingMessages
The chat identifier will be specified in the
"chatId"field
Example of a message in the journal:[ { "type": "incoming", "idMessage": "1769676078000", "timestamp": 1769676078, "typeMessage": "textMessage", "chatId": "10000000", "chatType": "user", "textMessage": "I use GREEN-API to send this message!", "senderId": "10000000", "senderName": "Vasilisa the Wise", "senderType": "user", "senderContactName": "Vasilisa the Wise", "deletedMessageId": "", "editedMessageId": "", "isEdited": false, "isDeleted": false } ] -
Using the method for getting the contact list GetContacts
The chat identifier will be specified in the
"chatId"field
Contact example:{ "chatId": "10000002", "name": "Frog Princess", "contactName": "Frog Princess", "type": "user" } -
Using the method for checking whether an account exists by phone number CheckAccount.
The chat identifier will be specified in the
"chatId"field
Response example:{ "exist": true, "chatId": "10000000", "username": "username", "phoneNumber": 79876543210, "fromCache": false }
Sending messages#
It is recommended to always send messages by the chat identifier chatId. Use the phone number, username or channel name in the @username format only to get the chatId using the CheckAccount method.
Sending messages by chat identifier#
It is recommended to send messages by the chat identifier (chatId).
- If the chat identifier is known, use it in the message sending methods.
- If the chat identifier is unknown, first use the CheckAccount method, get the
chatIdvalue, and then use thechatIdin the message sending methods.
Sending messages by phone number#
To maintain backward compatibility with previous versions of the interface, it is allowed to specify the client's phone number in the phoneNumber@c.us format as the chat identifier in the message sending methods.
It is recommended to first get the chat identifier using the CheckAccount method, and then send messages by the received chatId value rather than by the phone number.