Sending chat message from google app script
Asked Answered
T

4

9

I already developed applicaton for google app script that can send email messages, but right now there is a need for me to send gtalk chat/xmpp message to user from my script. my question is, is it possible for me to send gtalk chat/xmpp message directly from google app script? if it is not possible then is there any work around about this?

Tletski answered 5/7, 2012 at 6:44 Comment(2)
finally I can solve the problem by using google app engine. I create a servlet that can send xmpp message from there, and I can access google app engine from google app script by using HTTP POST request.Tletski
Can you share how it's done?Janeth
C
8

Basically, there are two types of messages you can automate through the Google App script.

  1. Synchronous: building a bot that can respond to user inputs.
  2. Asynchronous: specified trigger-based messaging systems. like submitting a google form or time-based.

Let's talk about Asynchronous

You can do it by Using incoming webhooks.

  • Create a Google Chat Room > Create a webhook URL. click_here
  • Use this Code:

function myFunction() {


    var WebWhooklink = "PEST_YOUR_WEBHOOK_URL_HERE"
    
    var message = { text: "Hello Chat"};
    var payload = JSON.stringify(message);
    var options = {
            method: 'POST',
            contentType: 'application/json',
            payload: payload
    };
  
    var response =  UrlFetchApp.fetch(Webhooklink, options ).getContentText();
}

Chastise answered 30/10, 2020 at 17:19 Comment(3)
I didn't expect to find such a great solution in this post, but your snippet was great for my case! Thank youChemosh
This is what I was looking for exactly and it works!!!! Thanks a ton!Allare
Wonderfull, bossFreezedrying
F
2

There is no built-in support for sending Google Chat messages. You can file a feature request on the issue tracker.

Foetus answered 19/7, 2012 at 0:28 Comment(0)
C
0

If you are able to make HTTP requests to external services from with in a google app script then you might be able to use an HTTP to XMPP gateway such as this:

http://chatmongers.com/blog/introducing-the-chatmongershttp-to-xmpp-gateway/

There would be a number of constraints you may still have to work through. The most common one being that privacy extensions block all messages from users that are not in the destination user's roster, but that's going to be a problem no matter how you manage to get XMPP messages sent.

Cousin answered 5/7, 2012 at 18:56 Comment(0)
D
0

According to this link, adding Webhooks is not available to personal Google accounts.

Despoliation answered 27/3 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.