Sending a message to a chat

1,509 views
Skip to first unread message

Santiago García

unread,
Apr 12, 2023, 7:09:15 PM4/12/23
to Google Apps Script Community
Hello everyone,

I'm pretty new using Apps Script

I have a work to do. I need to send a chat message from my account to another one using Apps Script. 

I know I can send an email using MailApp.sendEmail , but I need to send a chat, theres a way to do this?

Thanks

Ian Crew

unread,
Apr 12, 2023, 7:14:27 PM4/12/23
to google-apps-sc...@googlegroups.com
I’m not an expert myself, but it looks like https://developers.google.com/chat/api/guides/crudl/messages only includes Python examples at this point, so maybe the answer is “not yet” in terms of Apps Script? (I suppose you could interact with the Chat API as an “External API” but that’d probably be a lot of work.)

Hope that helps, at least a little,

Ian


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/410221c3-cb65-4ecf-bac6-2b2da2f33d36n%40googlegroups.com.

 

Ian Crew

Solutions Architect
Productivity & Collaboration Services
Berkeley IT

Nerio Villalobos

unread,
Apr 13, 2023, 7:24:10 AM4/13/23
to google-apps-sc...@googlegroups.com
Yes, it's possible to send chat messages using Apps Script. Google provides a Chat API that you can use to send messages to specific rooms or direct messages.

Here's a basic example:

function sendChatMessage() {
  var message = {
    text: "Hello, this is a test message."
  };

  var space = "SPACE_ID"; // Replace with the ID of the room or user you want to send the message to.

  var response = ChatApp.newMessage()
    .addUser(space)
    .text(message.text)
    .send();
}

In this example, we create a message object containing the text of the message we want to send. We then specify the space (room or user) we want to send the message to.

Finally, we create a new message using ChatApp.newMessage() and add the space and text properties. We call the send() method to actually send the message.

Note that in order to use the Chat API, you'll need to enable the "Hangouts Chat API" in your Google Cloud Platform project and set up authentication. You can find more information on how to do this in the Google Chat API documentation.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/410221c3-cb65-4ecf-bac6-2b2da2f33d36n%40googlegroups.com.


--
__________________________
Nerio Enrique Villalobos Morillo
Buenos Aires, Argentina
Reply all
Reply to author
Forward
0 new messages