Chat identifier#
Beta version
The functionality is in beta. Features may change and may also work unstably.
The chat identifier (chatId) is a unique marker needed to send messages correctly through the GREEN-API. It can belong both to a person and to a group.
Example of a personal chat identifier: chatId = "49547665464"
Example of a group chat identifier: chatId = "340282366841710300949128174631143137232"
Important
The account identifier is a 64-bit number, and the group thread identifier is a 128-bit one. The ranges do not overlap, so a personal chat is distinguished from a group one by the length of the value.
The identifier is presented as a string: the group chat value does not fit into a 64-bit integer, so it should not be converted to a number.
There are no negative values and no @c.us / @g.us suffixes in Instagram: such a value is rejected by a method with a 400 error.
How to get the chat identifier?#
The chat identifier can be obtained:
-
When handling incoming notifications
The chat identifier is specified in the
"senderData": "chatId"field
Example of a notification:{ "typeWebhook": "incomingMessageReceived", "instanceData": { "idInstance": 5100000000, "wid": "74857974059", "typeInstance": "instagram" }, "timestamp": 1766486400, "idMessage": "32992354783594572492903878028689408", "senderData": { "chatId": "49547665464", "chatName": "GREEN-API", "chatUsername": "@green_api", "chatType": "user", "sender": "49547665464", "senderName": "GREEN-API", "senderUsername": "@green_api", "senderType": "user" }, "messageData": { "typeMessage": "textMessage", "textMessageData": { "textMessage": "I use GREEN-API to send this message to you!" } } } -
Through the incoming messages journal LastIncomingMessages
The chat identifier is specified in the
"chatId"field
Example of a message in the journal:{ "type": "incoming", "idMessage": "32992354783594572492903878028689408", "timestamp": 1766486400, "typeMessage": "textMessage", "chatId": "49547665464", "chatType": "user", "textMessage": "I use GREEN-API to send this message to you!", "senderId": "49547665464", "senderName": "GREEN-API", "senderUsername": "@green_api", "senderType": "user" } -
By the method that gets the list of chats GetChats
The chat identifier is specified in the
"chatId"field
Example of a chat:{ "chatId": "49547665464", "name": "GREEN-API", "username": "@green_api", "type": "user" } -
By the GetContactInfo method - if you only have a username.
The chat identifier is specified in the
"chatId"field
Example of a response to the request{"chatId": "@green_api"}:{ "name": "GREEN-API", "username": "@green_api", "avatar": "https://instagram.ftse3-2.fna.fbcdn.net/v/t51.2885-19/495386024_18031684346649465_5390906708136372152_n.jpg?efg=eyJ2ZW5jb2RlX3RhZyI6InByb2ZpbGVfcGljLmRqYW5nby41MDAuYzIifQ&_nc_ht=instagram.ftse3-2.fna.fbcdn.net&_nc_cat=109&_nc_oc=Q6cZ2gFYb76TFMAltxyIuECYSkeKF15EWC0Ewtgt_FxzjEto8qeTbbYkzC4i5Mr2sPRmxCw&_nc_ohc=JEfpfr8uH-EQ7kNvwFa8Qqc&_nc_gid=A4BiW9omBwmCnTODEk03_g&edm=APs17CUBAAAA&ccb=7-5&ig_cache_key=GKj9hh15Gy_suA9AALgnvbsWWdBKbvEnAQAB0j-ccb7-5&oh=00_AQKIjxJWaZU_pmN8R0orM_ejwdU76mlR8XrQ08loqbKeGg&oe=6AB7F464&_nc_sid=10d13b", "chatId": "49547665464", "chatType": "user", "description": "IT-компания, которая разрабатывает шлюз WhatsApp API для отправки сообщений, рассылок и ботов на PHP, NodeJs, JavaScript и Python, 1С.", "isVerified": false, "isPrivate": false, "followersCount": 143, "followingCount": 5, "postsCount": 128 } -
By the method that checks whether an account exists CheckAccount.
The chat identifier is specified in the
"chatId"field
Example of a response:{ "exist": true, "chatId": "49547665464", "username": "@green_api" }
Sending messages#
The owner can change the username of an Instagram account at any moment, while the numeric identifier remains unchanged for the whole lifetime of the account. That is why it is recommended to store the chatId in your database and to use it in the API methods.
Addressing by the 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 and others.
- If you only know the username, specify it with the
@prefix inchatId, or get thechatIdbeforehand by the CheckAccount method.
Addressing by username#
Instead of the account identifier you can specify the contact's username - in the same chatId field, with the @ prefix:
{
"chatId": "@green_api",
"message": "I use GREEN-API to send this message to you!"
}
The separate username field is accepted by the CheckAccount method only: the other methods do not accept it and answer 400 with the text 'username' is not allowed.
A group thread is addressed only by the numeric
chatId: a group has no username.
Read also: