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?
Basically, there are two types of messages you can automate through the Google App script.
- Synchronous: building a bot that can respond to user inputs.
- 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();
}
There is no built-in support for sending Google Chat messages. You can file a feature request on the issue tracker.
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.
According to this link, adding Webhooks is not available to personal Google accounts.
© 2022 - 2024 — McMap. All rights reserved.