How to add forwarding rule in Google admin routing settings using Google API? - google-api

In admin settings in Google you can find section for Gmail routing. It's Apps > Google Workspace > Settings for Gmail > Routing. There, at the bottom of the page, you can find Email forwarding using recipient address map.
Here, you can add rule to forward emails from one email to another. And I'm wondering, if it's possible to add this rule using Google API.
Probably, I have found it, but I am really not sure. Here it is, from Gmail API. But it says only about auto-forwarding, and I guess, it's not about creating forwarding rules, like on screenshot.
So, my question is - is it possible to add forwarding rules using Google API?

I think you may be looking for Managing Filters
Filters can automatically add or remove labels or forward emails to verified aliases based on the attributes or content of the incoming message.
# create gmail api client
service = build('gmail', 'v1', credentials=creds)
label_name = 'IMPORTANT'
filter_content = {
'criteria': {
'from': 'gsuder1#workspacesamples.dev'
},
'action': {
'addLabelIds': [label_name],
'removeLabelIds': ['INBOX'],
'forward': "forwardTo#daimto.com"
}
}
# pylint: disable=E1101
result = service.users().settings().filters().create(
userId='me', body=filter_content).execute()
I haven't yet figured out how to get it to forward but the documentation says it should be able to.
i found it under action just add forward

Related

Google Meet integration api (like Hangouts app for Slack)

I want to utilise Google Meet api, which is used in Hangouts integration for Slack, description follows
TL;DR:
Links such as https://meet.google.com/new?gid=123&gd=qwe987 can be generated, so a modal is shown which can ask user's confirmation and then some request is sent from user's browser (where the Google Meet page is opened) to some endpoint (probably it is determined from gid which seems to be google application id). Is there a way to configure my application to have a webhook, so I can generate these custom links?
There's Google+ Hangouts app for Slack. Here's how it works (after you add the app in your workspace):
you send /hangout command in any Slack channel
slackbot sends an "Only visible to you" message in this channel with a link to start a new hangout. it looks smth like this (I changed data in the link): https://meet.google.com/new?gid=691521906844&gd=THTJ30X6W%7CU01113BD13M%7CD01113BDB5Z%7Csuren%7C%7C1846381238693%7C1%7CB01QFGG5GJF%7CE1MDm4DWcuVa0RbN5ZT9o5KF
when you visit the link, a new meeting is started instantly, and the page shows modal with text "To bring others into this video call, post a link it to your Slack channel" with buttons 'Cancel' and 'Post'.
when you click 'Post', a new message is sent to the Slack channel, where the command was sent. Text is "#Suren Khorenyan has started a Google+ Hangout and would like you to join. Join Hangout." and contains a link to the meet, which was created previously
How can I utilise this integration for another app, like Mattermost (or anything else like Telegram chats via bots)?
As I see, data in the url slightly changes. Probably it's payload for Google Meet to trigger Slack to send a message with link to the channel.
gid seems to be something like google app id
gd seems to be something like google data. If I url-decode it, it becomes THTJ30X6W|U01113BD13M|D01113BDB5Z|suren||1846381238693|1|B01QFGG5GJF|E1MDm4DWcuVa0RbN5ZT9o5KF. This is some kind of payload, separated by pipes (obviously), but I don't know what any part of this means (suren is my username in the Slack workspace, probably this is used for creating an invitation message).
When I click Post, this happens:
a new POST request to https://hooks.slack.com/services/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 is sent with form-data
hangout_id: 1812381238693
hangout_url: https://meet.google.com//abc-iuqx-def
a new message is posted to the Slack channel
Google meet somehow knows where to post back! Is this configured at the Google application (application id is provided via gid)? How can I configure my application for such behaviour? Where can I setup webhook url?
If we breakdown the request, we can see that url contains some parts of the gd payload:
THTJ27X6W - this is the first part of the gd payload
B01ABCD5GJF - last but one
E1MDm4DWcuVa0RbK5ZT9o5KD - the last part of the gd payload
and form-data contains:
hangout_id - this is in the gd payload after my name
hangout_url - obviously, this is the url for the new created meeting
How can I change it for my needs?
I created a new application at Google APIs dashboard (here console.developers.google.com/apis), but can't find any docs for this integration. There's Google+ Hangouts API in API Library, but it says Apps will continue to function until April 25, 2017..
I tried to approach it from another side:
In the API Library there's Google Calendar. I found mattermost-hangout app on GitHub (had to update it a bit, so it works with updated api). Here's how it works:
oauth2 for authorising at google (single account)
it handles POST request, which is meant to be received from Mattermost (triggered by a slash command),
creates a new calendar event using Google Calendar API (with conference),
takes hangouts url from the response and sends a new message in the Mattermost channel with invitation to join the meeting.
But it has some downsides:
you have to use one account to authorise all event creation events (yeah, it can be upgraded to authorise any number of users, but it'll be inconvenient. why to force anyone to provide access to their Google Account, when Google Meet authorisation just happens in browser, we don't need to create events)
account, used for auth, now has events in his calendar. of course, events can be deleted, but it's not the way.
Is there any documentation on utilising gid and gd params?
Generally, I want to find a way to configure a webhook in my app, so when Google Meet finds my application's ID in the gid query param, it looks at the app's config and sends a request to my app (previously configured endpoint (I assume it works this way)).
Of course there's a chance that it's some kind of internal API and it cannot be used by everyone, but I could not find any information on this.

How to send a message to google hangouts with python?

I am trying to create a simple "chat bot" for google hangouts that sends regular messages on a chat. I found this documentation but I find it tremendously complicated.
It contains a "Complete example" but I am not sure about how to find the "space" ID for an existing google hangout chat. This is nowhere explained. How do I find the "space" ID for an existing google chat?
And in addition: Is there a SIMPLE (!!!) documentation somewhere how to just simply post a message to an existing chat?
Answer:
You can either use spaces.list to get a list of spaces the bot is a member of followed by spaces.get for additional information on the space, or alternatively set up a room-specific Webhook.
Additional Information:
To send messages to a room without a respond trigger, you must use a service account
Bot-initiated message documentation can be found here.
Important Note: You can only use the Google Hangouts Chat API if you have a Google Workspace account - it will not work with Gmail alone. The second solution, which uses a Webhook, requires access to https://chat.google.com which is only available to Google Workspace domains. Unfortunately this is not at all possible using a consumer #gmail.com account.
Using the Hangouts Chat API:
Once you have a service account set up as per Step 1 on this page, you can download the credentials for the service account from the Google Cloud Project UI, by clicking on the ⋮ button to the right of the service account name, and following the Create key button and selecting JSON as the key type. Make sure to save this file well as there is only one copy of this key.
With this JSON file downloaded, you can use it in your python code as the credentials when setting up your service object:
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
scopes = 'https://www.googleapis.com/auth/chat.bot'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'credentials.json', scopes)
chat_service = build('chat', 'v1', http=credentials.authorize(Http()))
To make the spaces.list request, you can use this newly built chat_service, and extract hte list of spaces from the response:
def extract(n):
return n['name']
spaces_list = chat_service.spaces().list().execute()
all_spaces = map(extract, spaces_list['spaces'])
You can then use one of these spaces to send a message from the python program:
response = chat_service.spaces().messages().create(
parent=all_spaces[0],
body={'text': 'Test message'}).execute()
print(response)
Things to Remember:
Make sure the Hangouts Chat API is enabled for your project at https://console.cloud.google.com
Once enabled, make sure the bot is configured with a name, logo and description.
The Connection settings for the bot must also be set up; the method is not so important; you can for example choose Apps Script project and enter the deployment ID for an empty deployed project.
Using a Webhook:
Instead of directly using the API, you can instead set up a webhook for a specific chat and with a hardcoded URL, you can send messages to a room from an external script.
The full steps are set out on this page but I'll go through it here also.
Go to the room to which you wish to send a message at https://chat.google.com, and from the dropdown menu next to the room's name, select Manage Webhooks.
Enter a name and an optional avatar for your bot, and press SAVE. This will give you a webhook URL to use in your python script.
Locally, make sure you have httplib2 installed in your environment, and copy the following script into a new .py file:
from json import dumps
from httplib2 import Http
def main():
"""Hangouts Chat incoming webhook quickstart."""
url = 'webhook-url'
bot_message = {
'text' : 'Hello from a Python script!'}
message_headers = {'Content-Type': 'application/json; charset=UTF-8'}
http_obj = Http()
response = http_obj.request(
uri=url,
method='POST',
headers=message_headers,
body=dumps(bot_message),
)
print(response)
if __name__ == '__main__':
main()
Manking sure to replace the webhook-url string with the webhook provided in the Chat UI in the previous step.
Now you can just save the file and run it - this will send a message automatically to the aforementioned chat space:
References:
Creating new bots | Google Chat API | Google Developers
Method: spaces.list | Google Chat API | Google Developers
Method: spaces.get | Google Chat API | Google Developers
REST Resource: spaces | Google Chat API | Google Developers
See this API, it's very interesting:
https://pypi.org/project/hangups/
There is some projects who uses Hangups, among then, HangupsBot:
https://github.com/xmikos/hangupsbot

Mentioning Guest using Slack Bot?

I have numerous guests in my channel.
I'd like my bot to mention these guests in a # mention, but bots don't seem to see channel guests. It find other full users fine, just none of the guests.
Is this an intentional limitation of Slack or does the bot require more permissions?
I'm using the slackclient module (Python) and making the following call:
sc.client.api_call(
"chat.postMessage",
channel="#channel",
link_names=1,
text="#aaron.layfield <-- Working #guest.name <-- Not working This is a message."
)
If you want to link to users from inside of your message, the best format to use is <#USERID> instead of #username. This is because Slack has moved away from using usernames, and towards a more flexible concept of display names, which aren't guaranteed to be unique or immutable.
So in this case, you would do something like
curl --request 'POST' 'https://slack.com/api/chat.postMessage?token=xoxb-21321321-1231321321321-dsfasdgdsfaghsdfhsdfh&channel=C9UFK5F5S&text=Hey <#UFBKH3B63>'
Which would render as
Hey #Colm Doyle
As already explained by Colm's answer the #username syntax is depreciated and you should use the ID syntax instead for mentions.
To get the IDs for your guest users call users.list to get a list of all users in your workspace. Then iterate through that list to match guest name with ID.

Turn off Mandrill transactional email URL tracking

I use simple SMTP settings to send emails from my app with Mandrill. Mandrill however hijacks the links and injects its own URLs so that link is rerouted via their servers. That results with user seeing the mandrill URL in their browser before going to the the right page. Any way to turn that off?
I looked through the settings and could not find it.
Also it's simple to disable click-tracking for individual link by mc:disable-tracking parameter.
<a href="//example.com" mc:disable-tracking>
Click here to confirm your email
</a>
The extra parameter will be removed when the email is sent, and no click-tracking will be applied to this link.
See: documentation.
There's an option on the Sending Defaults page in your account that is for click-tracking (should be a drop down menu, near the top, just below the checkbox for tracking opens). What you select there will be the default option applied to all messages, unless you provide a different per-message setting for click-tracking. With SMTP, you can set click-tracking on a per-message basis using custom SMTP headers. More information about using SMTP headers to customize this can be found in the Mandrill KB here.

Joomla : Could not instantiate mail function

I have developed a website in joomla, and I have a contact us page, in that the form works fine only when I use to send an email from the same domain
Eg :
From : rimaz#abcd.com
To : john#abcd.com
But when I send to a different domain the form gives an error as "Could not instantiate mail function."
Eg :
From : rimaz#abcd.com
To : john#gmail.com
Can anyone explain me about this problem ??
Instead of debugging your providers SMTP / email setup you can use the new mandrill service from the guys who do mailchimp - Mandrill ( http://blog.mailchimp.com/public-beta-of-mandrill-smtp-email-service/ ) with the plugin :
http://extensions.joomla.org/extensions/content-sharing/mailing-a-distribution-lists/20624
Mandrill is a plugin that allows your Joomla installation to send transactional emails. The only thing you need to do is to provide your Mandrill API key and enable the plugin. After that all emails (new user registration, password reset etc) will be send through the Mandrill service.
Mandrill Features:
Uses MailChimp's awesome email delivery engine instead of your server
Tracks opens and clicks so you know how effective these emails are to your users . Now you can > see what you need to change to make them
more effective.
Has pretty, visual reports of the email results
Allows you to tag the emails and see your stats filtered by tag
Why would understanding transactional emails be important for you. An example is when a user signs > up on your site an email is sent via Joomla. But, you get no reports to understand how effective that email did. These emails are sent as instructions to your users telling them a message you want them to understand. Where they designed good? Was the content well written? Was it structured properly? This is hard to say when it goes thru Joomla but now you will understand all this when the emails goes thru Mandrill.
This is a setting from your host. YOu can ask them for help in figuring out how to make it work, but they are trying to prevent you from using their hosting to spam people.
Sometimes it is possible to work around it but not always.
This usually happens due to restrictive mail server settings, which you most likely don't have influence on with shared hosting.
If you have more control over the server, you should fix the mail server settings.
If not, the easiest way is to use Joomla's ability to send mails using any SMTP mail account. Create a mail account for Joomla, and enter the credentials in Joomla's configuration. Joomla will then use that account to send mails. So will extensions, if they are properly written.

Resources