I have a working google chatbot that can send a message to a specific room
that the chatbot is subscribed to using the following code:
$client = new Google_Client();
$client->setAuthConfig('../service-account.json');
$client->addScope('https://www.googleapis.com/auth/chat.bot');
$service = new Google_Service_HangoutsChat($client);
$message = new Google_Service_HangoutsChat_Message();
$message->setText('@Leon Vismer Testing a message.');
$message->setAnnotations([$annotation]);
$service->spaces_messages->create('spaces/SPACE_REFERENCE', $message);
However what I am trying todo is direct the message to a specific user inside the room
using a mention. I tried using annotations but that does not seem to work. I get a notification of a new message inside the room but the @mention is not a proper annotation to the specific user.
I tried using:
$user = new Google_Service_HangoutsChat_User([
'name' => 'users/NUMBER_TO_THE_USER',
'displayName' => 'Leon Vismer',
'type' => 'HUMAN',
]);
$annotation = new Google_Service_HangoutsChat_Annotation([
'type' => 'USER_MENTION',
'startIndex' => 1,
'length' => strlen('@Leon Vismer'),
'userMention' => new Google_Service_HangoutsChat_UserMentionMetadata([
'user' => $user,
'type' => 'MENTION',
])
]);
Can a chatbot in a way initiate a conversation to a specific user like this?