Social media profiles

Contents

  1. Create social profile
  2. Update social profile
  3. Opt-out
  4. Bot

Create a social profile

When a conversation from a new client comes to the Kommo account, it’s essential to create a profile for the client in the account.

You can import the contact name, the identifier (maybe telephone), and the image from the client profile in the chat service and suggest creating a new contact in the Kommo account.

After getting the information, you can check the existence of the contact using the search by phone method. If not, you can add it using the create contact method. Then you can create the chat and link it to this contact or pass the contact info in the request body. From then, the message exchange can happen, then you can create an incoming lead or lead related to this contact.

use Amojo\Entity\User\UserProfile;
//class UserProfile implements EntityInterface, holds the user’s information

string $name = '',
string $avatarUrl = '',
string $email = '',

$userProfile = new UserProfile(self::DEFAULT_NAME);

if (!empty($name)) {
    $userProfile->setName($name);
}
if (!empty($avatarUrl)) {
    $userProfile->setAvatarUrl($avatarUrl);
}
if (!empty($email)) {
    $userProfile->setEmail($email);
}

Update the social profile

Since the clients can update their profiles in the chat service, whether they update their info or a new person has taken over the job, you can synchronize the updates into Kommo. The client information stored in Kommo includes the name, the image, and a list of phone numbers.

You can perform this use case once the user opens the contact’s chat in Kommo, check for the client’s profile in the chat service, and, if any changes have happened, pull them. Or you can provide a separate function to synchronize one or all contacts.

Opt-out

Clients can opt out of receiving any further messages from a business. This act is known as closing a conversation, which might prevent the business from sending messages to this client, or some messengers just stop receiving the messages on the client side.

In some messengers, opting out is different from blocking. While blocking a business stops the business from sending messages to the client, it also eliminates the last from being able to send messages to that business. Pressing the button to opt-out of marketing messages sends a request to the user to remove the client from its marketing mailing list. Still, it allows individual messages between the client and the business to continue. This way, the client can still send particular messages, including questions about the user’s products or services. The user can answer questions and send messages about client transactions, such as shipping updates.

In other messengers, opting out acts like blocking, and the user can’t send further messages to the client. If they try, messages will send an error response, and it’s a requirement that integrators prevent such behavior.

To implement this use case, you can provide a pop-up notification about this and prevent them from sending messages or alert them in a way to commensurate with the messenger service’s business condition.

class CloseConversationUseCase
{
    private AmoJoConversationRepository $amoJoConversation;
    private AmoJoClient $amoJoClient;
    public function handle(CloseConversationTask $task): void
    {
        $amoJoConversation->setActive(AmoJoConversation::INACTIVE);
        if (!$amoJoConversation->save()) {
            throw BusinessLogicException::create('Save active error');
        }
        $result = $this->amoJoClient->sendMessage(
            'Conversation with this client was closed',
            $amoJoConversation->getConversationId(),
            $amoJoConversation->getName(),
            $amoJoConversation->getAvatarUrl()
        );
        $task->setSuccess();
    }
}

Bot

If the message was sent externally from a bot, you could inform the client that a bot is answering them, not a real user.

Here is an example of sending a message from Kommo, putting the message sender as the responsible user for the client if the message was sent from a bot.

public function sendMessageFromBot(string $body, string $amojoConversationId, string $amojoClientId, string $scopeId)
    {
        $chat = new Chat($amojoConversationId);

        $message = new Message('text', $body);

        $userProfile = new UserProfile('Chat Application');
        $senderProfile = new UserProfile('Chat Bot');
        $sender = new User('2f34d6f5-bfc9-4539-b0c9-c72bfe4ed448', $senderProfile, 'fa81f8b3-a31b-4d0a-9e4b-fad2a84206a7');
        $receiver = new User($amojoClientId, $userProfile);

        $sender = new Sender($sender);
        $receiver = new Receiver($receiver);

        $messageUser = new MessageUsers($sender, $receiver);

        $messageEvent = new MessageEvent($chat, $message, $messageUser, time(), false);

        return $this->apiClient->sendMessage($messageEvent, $scopeId)->getBody()->getContents();
    }

For a more smooth experience, we suggest support different rich messages.