Is it possible to get the amount of emails sent and received in workspace by Google API? - google-api

I need to get the amount of emails sent and received in a Google Workspace.
Basically, I want to know if it is possible to get the data of this report by some Google API.
I get this print directly from Google Admin.
I tried using Gmail API.
const { google } = require('googleapis')
const oAuth2Client = require('./oauth.js')
const gmail = google.gmail({
version: 'v1',
auth: oAuth2Client
});
await gmail.users.messages.list({ userId: 'me' }) // success
await gmail.users.messages.list({ userId: 'othermail#domain.com' }) // permission error
But I can only get the emails from the authenticated account. And I need from all accounts in domain.

To list all messages in every account, you will need to use domain-wide delegation to impersonate the account.
However, it's easier and more performant to find the closest property in the Reports API that fits what you need, like num_emails_exchanged.

Related

As a content owner, how do I get access to content owner reports through YouTube Reporting API?

I'm using the YouTube Reporting API successfully to create channel reports, however I can't seem to access content owner reports. The account I'm authenticated in is a content owner, but when I tried to create a job for a content owner report I get a 403.
I think this is similar to this person's issue: Youtube reporting API returns 403 for content owner reports
One wrinkle is that when I get the channel via the api the contentOwnerDetails field is empty:
const { data } = await youtube.channels.list({
auth: oauth2Client,
part: 'snippet,contentDetails,statistics,topicDetails,contentOwnerDetails,localizations',
mine: true,
maxResults: MAX_RESULT_SIZE,
pageToken
});
However, I am a YouTube partner and this account is definitely a content owner. Is there some step I need to take to get a content owner id, or is there an API scope I'm missing (e.g., youtubepartner)?

Relationship between Teams Messaging Extension with action command, the underlying bot and access via Graph API

I want to call a messaging extension (with action command) and access Graph API via a bot for getting different resources of the channel (e.g. retrieve all messages or get replies for my message).
In the examples from Microsoft it is stated as a prerequisite that I have to do the "Bot channels registration" so that the access of the bot to the Graph API via OAuth2 works.
Do I really need this channel registration? Or is there another way?
As a test, I had created a azure free trial, with which I performed the "Bot channels registration" and could also save the ID and secret for the Graph Api access in the registration. With this I had success. Now the 30 days testing period is over and I'm interested in whether it would work without.
Thanks for your help
Update:
Thats my code to initialize graph api:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(AppId)
.WithClientSecret(AppSecret)
.WithAuthority(new Uri($"https://login.microsoftonline.com/{Tenant}"))
.Build();
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
AuthenticationResult authenticationResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
return Task.FromResult(0);
}));
For OAuth authentication, you need to register the bot with azure for sure.

Integrating Azure Bot in Web Application

We have a scenario where a user would first login to web application before starting a conversation with Azure Bot.
My question is how do we ensure bot will only allow user to ask financial questions related to his own accounts considering the bot is capable of answer questions related to financial holding of the person logged in.
Basically is there a way to pass principal object to the bot before the conversation starts. If yes how do we pass those details.
The BotFramework currently does not support single sign-on; however, the BotFramework Web Chat Development team has recommended different approaches to create a single sign-on experience and is currently working on developing a sample.
The main approach recommends piggybacking the authentication token on every outgoing message by adding it to the activity's channel data. To do this, you can create a custom middleware that appends the additional data. Take a look at the code snippet below.
const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
// The channelData submitted here is very similar to HTTP cookies and vulnerable to forgery attack.
// Make sure you use signature to protect it and verify the signature on the bot side.
// To minimize unexpected behaviors, we recommend to treat the "action" object as if it is immutable.
// We use simple-update-in package to update "action" with partial deep cloning.
action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'token'], () => token);
}
return next(action);
}
);
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
// We will use a custom version of Redux store, which we added middleware to handle backchannel messages.
store
}, document.getElementById('webchat'));
On the bot side, you can retrieve the token from the channel data and use it to make various requests. For more details on adding data to outgoing activities, take a look at this sample.
For more details regarding recommended approaches, take a look at this issue on GitHub. The Web Chat Development team is also using it to track the progress of the sample.
Hope this helps.

How to design bot with passing token from client app

I have to design a bot that can answer what my app users are asking about their project. Answers will be the implementations of certain APIs. These APIs that my bot will be using to give answers are secured by user-specific authentication tokens. As of now, I have written a bot using Microsoft bot framework and LUIS that understands certain utterances and can give answers with calling project APIS.I am confused about how to do these things :
How to pass user authentication token to bot? This toke is generated using user credentials (usename+password). Inside my bot code, I can't use username/password for generating the token.I need to pass them from client app only.
How to pass project Id to the bot about which user is asking the question? The user might be calling the name of the project, or will select the project from a list. The bot should be intelligent enough to change answers based on project Id.
As of now, I am handing second part using LUIS utterances + Entity combination. So my question(utterance is ): "tell me what's new in {projectid}" where projectid is my project entity.
But for the first question, I am still looking for the solution. Please suggest.
You will need few modification in your bot to use DirectLine API instead of webchat. Directline API gives you flexibility to send your own data to Bot. There are few reserved properties inside Activity.From from which you can read your data.
var userProperties = [];
userProperties.push({
projectId:
{Project_Id_Will_Be_Sent_Using_This},
UserToken:
{User_Generated_Token}
});
BotChat.App({
directLine: { secret: 'BOT-SECRET-KEY' },
user: { id: '', name:'', properties:userProperties },
bot: { id: 'YOUR-BOT-ID' },
resize: 'detect',
}, document.getElementById("bot"));
Please revert if you need any help around this.

Can't cancel a stripe subscription through Parse API when user has more than one subscription

I am building site that allows users to signup for multiple subscriptions. The Parse.com / Stripe API we use allows me to create multiple subscriptions for each user. However, if a user has more than one subscription, and I attempt to cancel any of them, I get an error that the user has more than one subscription and that I must identify which subscription I am referring to. The problem is, that I do attempt to pass the subscription ID to into the API (see below) but it just seems to get ignored. Stripe clearly supports this second parameter in their API, but the Parse documentation does not show a second "subscriptionId" parameter.
The following Parse Cloud Code (which works perfectly as long as the user has only one subscription)
Parse.Cloud.define("cancelStripeSubscription", function(request, response) {
Stripe.Customers.cancelSubscription(request.params.customerId, request.params.subscriptionId, true, {
success: function(httpResponse) {
response.success("Cancellation Complete");
},
error: function(httpResponse) {
response.error("Error: " + httpResponse.message);
}
});
});
Here is the relevant Parse/Stripe Cloud Code API - https://parse.com/docs/js/api/symbols/Stripe.Customers.html#.cancelSubscription
Here is the equivalent Stripe API clearly showing a second "subscriptionId" parameter. https://stripe.com/docs/api/node#cancel_subscription
I'm hoping that the Parse/Stripe module does support multiple subscriptions.
Thanks for any help!
Unfortunately, Parse's Stripe API library is pretty old and was built against an old version of the API when only 1 subscription was possible. You'd either just have to do 1 subscription per customer or generate the web request to Stripe's API yourself not using the library.

Resources