Have I missed some documentation or am I right in thinking there is no way to @mention someone in an AppSheet Google Chat App?
We want to be able to send someone a direct message when a task is assigned to them but, from what I can see and have experimented with, the only way to do this would be to make individual Botd for each user pre-filtered for that use to send them a DM, whereas it would be handy to @mention them in a Space instead, therefore only needing one Bot.
Any suggestions appreciated.
Solved! Go to Solution.
I found a solution so I thought I'd answer my own question to benefit others and as a reminder to me.
To @mention someone in a Google Chat via an AppSheet Chat App you need to use the USER_ID as specified in the Google Chat API Documentation: Messages that @mention specific users.
As an example if you have a field called "Google User ID" then the message text you should add to the Bot would follow this format
<users/<<[Google User ID]>>>
I was dubious it would work as I thought the parsing would get confused by the closing >>> but it does work as you can see in this screenshot:
I hope others find this useful.
I found a solution so I thought I'd answer my own question to benefit others and as a reminder to me.
To @mention someone in a Google Chat via an AppSheet Chat App you need to use the USER_ID as specified in the Google Chat API Documentation: Messages that @mention specific users.
As an example if you have a field called "Google User ID" then the message text you should add to the Bot would follow this format
<users/<<[Google User ID]>>>
I was dubious it would work as I thought the parsing would get confused by the closing >>> but it does work as you can see in this screenshot:
I hope others find this useful.
Hi Stephen,
I tried to use your method but it didn't work.
This is what I am getting:
"
<users/user1@org.com>
"
@Madhav_More if you look at my previous post (and refer to the documentation) the format is
<users/<<[Google User ID]>>>
that's [Google User ID] not the email address. You need to get the ID (it's a number) from the People API, etc.
Thanks Man, It works!!
Just to add it over here on how to get that User ID.
Go to https://developers.google.com/people/api/rest/v1/people/searchDirectoryPeople
On right hand side under "Query" type in email id of person in your org & "Readmask" as "names" . Execute and you now have Google User ID of that email.
Hi Madhav, can you elaborate more of the steps on how you could get the google user ID using email address? I am opening the URL you share but it is the documentation page, I cannot find a field to type in email addresses. Thanks in advance!
Hi Madhav, can you elaborate more steps on how you could get Google user ID by inserting email addresses. I opened the link you shared above but it's a documentation and I could not find a field where I could fill in an email address. Thanks in advance!
Click on the "API" mentioned at the Right hand side.
Fill the fields.
And execute at the bottom right side.
Thank you Madhav, sorry to have just replied. Really helpful!
Thank you for the useful tip @StephenHind !
Were you able to apply the mention to the text inside the card as well?
Also were you able to mention multiple users in a single message?
The card is a detail view from AppSheet, so you cannot do any kind of @mentinoning in there.
Yes you can mention multiple users as I've developed a bot to do that also.
Thanks for the reply @StephenHind ๐
@StephenHind , I've gotten this to work and am grateful for this posting, thank you!
Could you elaborate on the method for using a bot to mention multiple users? I'm afraid I'm trying to make it more complicated than it needs to be, thanks.
Literally just put in multiple <users/userid> tags, e.g.
<users/10494911XXXX160083053> <users/100966225XXXX76187181> <users/113075152XXXX7225095>
Again the userid is not the email address, but the number given by Google to that account.
Hello, I'm trying your solution but when I send the message this appear :
<users/<<100560793381605094554>>> updated a task
My code is : const message = `<users/<<${userId}>>>` + ' updated a task';
And my userId is from: response.people[0].names[0].metadata.source.id;
What's wrong please ?
@Lapouge how are you including the user tag into the chat message? We preformat the message in a LongText column called chatNote and then add the chatNote in the bot, e.g. here's the LongText
"<users/"&[Ticket].[Assigned To]&">
*"&[Status].[Name]&" - "&[displayTimestamp]&" by "&
IF(ISNOTBLANK([sender]), [senderName], [Consultant].[_ComputedName])
"*
"&[Note]&
IF(
ISNOTBLANK([groupUrl]),
"
<"&[groupUrl]&"|"&[subject]&">",
""
)
And here's what we include in the bot (outlined in red):
I'm not using Appsheet, I'm using Apps Script to try to send a message with a mentioned person.
This does not work using either the <users/[client id]> code or the <users/<<[client id]>>> code.
The scipt retrieves the client id with the API that Madhav_More mentioned. And I send the message with the classic API which sends messages in google spaces.
Do you have any idea why this isn't working?
@Lapouge no this thread is only referring to AppSheet (this is the AppSheet community) so the form at of
<users/<<[client id]>> >
only refers to AppSheet and how it adds it's fields to a template.
If you need help with Apps Script you may want to try the Google Apps Script Community instead.
Although it has been resolved, I would like to contribute with an example using Apps Script that is linked to a spreadsheet:
/**
* This script retrieves a user's ID in Google Workspace based on their email
* using the Admin Directory API and sends a message to Google Chat mentioning the user.
* Note: The Admin Directory API must be enabled in the Apps Script project.
*/
function sendChatNotification(userEmail) {
try {
// URL of the Google Chat webhook (replace with your own)
var webhookUrl = "YOUR_GOOGLE_CHAT_WEBHOOK_URL";
// Get the user ID using the email
var userId = getUserIdByEmail(userEmail);
// Create the message mentioning the user by ID
var message = `*Responsible:* <users/${userId}> has been mentioned in the incident.`;
// Prepare the payload with the message
var payload = JSON.stringify({ text: message });
// Define the request options
var options = {
method: "post",
contentType: "application/json",
payload: payload
};
// Send the message to Google Chat
var response = UrlFetchApp.fetch(webhookUrl, options);
Logger.log("Message sent to Google Chat: " + response.getContentText());
} catch (e) {
Logger.log("Error sending notification: " + e.message);
}
}
// Function to get the user ID based on the email
function getUserIdByEmail(email) {
try {
// Use the Admin Directory API to retrieve the user information
const user = AdminDirectory.Users.get(email);
if (!user || !user.id) {
throw new Error("Could not retrieve the user's ID.");
}
Logger.log("User ID: " + user.id);
return user.id;
} catch (e) {
Logger.log("Error retrieving user ID: " + e.message);
}
}
User | Count |
---|---|
18 | |
14 | |
11 | |
7 | |
4 |