Matching Mailgun Webhook response event to Mailinglist E-mail - javascript

So I am using Mailgun API to send E-mails and recently started using their mailing list feature as well.
When I send to the mailing list for instance: somelist#mg.address.com
It returns a single message Id.
However when I receive the webhook responses that messageId is not contained within the data, it gives the message ID pertaining to the individual address mail sent by server. (So if i send an e-mail to somelist#somedomain.com which contains 100 addresses, I will receive notifications with 100 different message ID's.
I could potentially match it up by subject, but that doesn't seem right.. What is the correct way to match the event to the mailing list email?

I was able to solve this by generating a random tag when sending the email and including it in the data.
https://documentation.mailgun.com/en/latest/api-tags.html

Every MailGun Event that you will receive will have message ID in it. Usually it may be found under message.headers.message-id. For instance, your event may look like this
{
"id": "ABC123...",
"message": {
"headers": {
"to": "somebody#somewhere.com",
"message-id": "20211012201139.1.XYZ...#somedomain.com",
"from": "you#somedomain.com",
"subject": "Test email"
},
"attachments": [],
"size": 29123
},
"event": "accepted"
...
}

Related

Commenting in real time using getstream

I'm working with the js/node api of getstream and I'm trying to add a realtime feature to the comments on the activities, but I'm receiving a 403 error, displaying I dont have permission.
I've tried using targetFeeds: '[timeline:userid]' but it wrecks the application.
Also I tried to use the notification feed as in the documents is being used, and I can set targetFeeds like this: '[notification:userid]' which obviously is not the desired thing to do because this will cause that every message on different activities of this user will be shown on the callback.
client.reactions.add("comment", activityId, {
"text": newComment,
"profileImage": 'https://i.pravatar.cc/300',
"timestamp": date,
"from": userId,
"id": foreignId,
},
{targetFeeds: [`CommentsFeed:${activityId}`]});
And the response of the 403 is the next one:
{
code: 17
detail: "You don't have permission to do this"
duration: "0.18ms"
exception: "NotAllowedException"
status_code: 403
}
The expected result is not having the 403, that will trigger the callback I implemented.
The default permission settings allow users to only write activities to their own feeds; in this case you are adding an activity to CommentsFeed:${activityId}.
You can request support (support#getstream.io) to whitelist this for you app(s). Just make sure to mention this case and include your applications.

Dialogflow : followEventInput

I want to use follow-up intent. My user says something which launch an intent, send a response and launch another one, which sends a response and launch another one... I use those function
function send_message_follow(res,output,token,quote,id,action,parametre){
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({
"fulfillmentText" : output,
"outputContexts": [
{
"name": id + "/contexts/connected",
"lifespanCount": 5,
"parameters": {
"token": token,
"quote" : quote
}
}
],
"followupEventInput": {
"name": action,
"languageCode": "fr",
"parameters": {
"param": parametre,
}
}
}));`
function send_message_final(res,output,token,quote,id){
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({
"fulfillmentText" : output,
"outputContexts": [
{
"name": id + "/contexts/connected",
"lifespanCount": 5,
"parameters": {
"token": token,
"quote" : quote
}
}
]
}));
However, output is not shown with send_message_follow. I works only with send_message_final. I could add the 1rst output as a parameter to catch for the other ones, but this shows only 1 block of message. I want 1 per intent.
Is there a way to fix this ? Thanks
No, there is no way to "fix" this. Follow up events are a way to redirect from the currently match intent to another intent. The currently match intent does not have a chance to respond before it is redirected. This means you will only have one response from the intent that is redirected to last. You can't compile response from multiple intent responses by redirecting through multiple intents with follow up events.
When a followup event is triggered from the webhook, the event specified in the webhook response is triggered. Triggering the event through a webhook sends the request back through Dialogflow for matching without responding to the user. The response to the user is sent as if the user triggered the event that was triggered in the webhook. After the second intent is matched by the event, Dialogflow will do any necessary work (like webhook calls or additional prompts for required parameters) and send a response back as if the second intent was the originally matched intent.
A user sends a request to Dialogflow.
"Intent 1" is matched by Dialogflow.
A webhook request is sent to your fulfillment server, which indicates that intent 1 was matched.
Your fulfillment server responds to the webhook request with a followup event response.
Dialogflow re-matches intent 2 based on the followup event sent in the webhook response.
Dialogflow sends a response to the user based solely on intent 2 being matched. Dialogflow may send another webhook call indicating intent 2 was matched, or send a prompt for unfulfilled required parameters (if configured) for intent 2.

How to send push notifications to multiple devices using Firebase Cloud Messaging

I was findind a way to deliver push messages from my expressJS server to my ionic app and I found GCM. With GCM I could deliver the message passing a list of tokens, like this :
sender.send(message, {
registrationTokens: deviceTokens
}, function (err, response) {
if (err) console.error(err);
else console.log('response' + JSON.stringify(response));
});
But as I found that GCM became FCM I was trying to do the same using FCM, but no luck until now. I've heard about sending topics but I couldn't find an example.
Can anyone give an example on how send topic messages using FCM ?
my FCM code: (working with just 1 token)
var FCM = require('fcm-node');
var serverKey = 'xxx';
var fcm = new FCM(serverKey);
var message = {
to: 'device-token',
notification: {
title: event.title,
body: event.information
}
};
fcm.send(message, function (err, response) {
if (err) {
console.log("Something has gone wrong! \n" + err);
} else {
console.log("Successfully sent with response: \n ", JSON.stringify(response));
}
});
I reckon you are using fcm push library for your push notification,
if you want to send same notification to multiple users then use "registration_ids" parameter instead of "to". this tag accepts an array of strings.
ex:
registration_ids:["registrationkey1","registrationkey2"].
note: limit is 100 key at a time.
I think it is documented pretty well by Google. Basically, there are two ways to send notifications to multiple groups:
Topic Messaging : You have the client subscribe to specific topics and then while sending notifications you just modify the request to target a specific topic. All the clients subscribed to that topic would receive the message.
POST request to this end point.
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=SERVER_AUTHORIZATION_KEY
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!"
}
}
How you subscribe to a specific topic depends on the device context. Documentation for Android and IOS are mentioned in the link I provide.
Device Groups : This is basically building on the approach you have provided you have the registration tokens of the devices you want to target. You can form a device group like so:
POST request
https://android.googleapis.com/gcm/notification
Content-Type:application/json
Authorization:key=API_KEY
project_id:SENDER_ID
{
"operation": "create",
"notification_key_name": "appUser-Chris",
"registration_ids": ["4", "8", "15", "16", "23", "42"]
}
The following request returns a notification_key which you can use in the to field to send notifications. Yes, You will have to save this notification_key somewhere and use it simply like:
POST request
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=SERVER_AUTHORIZATION_KEY
{
"to": "aUniqueKey", //This is your notification_key
"data": {
"hello": "This is a Firebase Cloud Messaging Device Group Message!",
}
}
Ofcourse, you can add and remove devices from the group and all the other fine control. Like I mentioned, it is all documented very well and should get you started without a hiccup.

Google People API get contacts emails

I need to get contacts emails with Google People API, but can't find a way to do it in docs. Currently I'm making the following request:
request.get('https://people.googleapis.com/v1/people/me/connections?access_token=tokenHere',
function (error, response, body) {
console.log(body);
});
And getting the following responce (I pin only the part of it, for example):
{
"resourceName": "people/c1705421824339784415",
"etag": "328OLZwdaiQ=",
"metadata": {
"sources": [
{
"type": "CONTACT",
"id": "17aae01d0ff8b2df",
"etag": "#328OLZwdaiQ="
}
],
"objectType": "PERSON"
},
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "17aae01d0ff8b2df"
}
},
"displayName": "testGoogleContact",
"givenName": "testGoogleContact",
"displayNameLastFirst": "testGoogleContact"
}
]
}
To achieve this you need to use the Google Plus API: This is what I found on the Google Plus API Documentation page:
You can get an email address for the authenticated user by using the
email scope.
The following JavaScript code example demonstrates how to:
Use Google+ Sign-In to authenticate the user and get a valid OAuth 2.0
access token.
Use the token to make an HTTP GET request to the
https://www.googleapis.com/plus/v1/people/me
REST endpoint. Parse the response and display the user's email
address.
The JSON should like something like this:
{"kind":"plus#person","etag":"\"xw0en60W6-NurXn4VBU-CMjSPEw/mjjYoraGfq3Wi-8Nee4F3k7GYrs\"","emails":[{"value":"**EMAIL**","type":"account"}],"objectType":"person","id":"Person ID","displayName":"FULL NAME","name":{"familyName":"LAST NAME","givenName":"NAME"},"url":"https://plus.google.com/USER","image":{"url":"https://lh5.googleusercontent.com/-RTcRn6jTuoI/AAAAAAAAAAI/AAAAAAAAEpg/Y6cMxfwtbQ4/photo.jpg?sz=50","isDefault":false},"placesLived":[{"value":"CITY","primary":true}],"isPlusUser":true,"verified":false,"cover":{"layout":"banner","coverPhoto":{"url":"https://lh3.googleusercontent.com/SybH-BjYW2ft1rzayamGLg_VwW7ocgnQ5cAxH3ROEpODvyaEODpYKW55gmAxCXDUvfKggQ4=s630-fcrop64=1,00002778ffffffff","height":626,"width":940},"coverInfo":{"topImageOffset":0,"leftImageOffset":0}},"result":{"kind":"plus#person","etag":"\"xw0en60W6-NurXn4VBU-CMjSPEw/mjjYoraGfq3Wi-8Nee4F3k7GYrs\"","emails":[{"value":"**EMAIL HERE**","type":"account"}],"objectType":"person","id":"116508277095473789406","displayName":"FULL NAME","name":{"familyName":"LAST NAME","givenName":"NAME"},"url":"https://plus.google.com/USER","image":{"url":"https://lh5.googleusercontent.com/-RTcRn6jTuoI/AAAAAAAAAAI/AAAAAAAAEpg/Y6cMxfwtbQ4/photo.jpg?sz=50","isDefault":false},"placesLived":[{"value":"CITY I LIVE","primary":true}],"isPlusUser":true,"verified":false,"cover":{"layout":"banner","coverPhoto":{"url":"https://lh3.googleusercontent.com/SybH-BjYW2ft1rzayamGLg_VwW7ocgnQ5cAxH3ROEpODvyaEODpYKW55gmAxCXDUvfKggQ4=s630-fcrop64=1,00002778ffffffff","height":626,"width":940},"coverInfo":{"topImageOffset":0,"leftImageOffset":0}}}}
Source: Google Plus API documentation
In case anyone else comes across this question: the solution to retrieving the email addresses of an authorized user's contacts, what the OP seems to want (not the authorized user's own email address) is at Why can't I retrieve emails addresses and phone numbers with Google People API?.
Explanation: If you look at the section under "Query Parameters" on https://developers.google.com/people/api/rest/v1/people.connections/list, you'll see that requestMask is a parameter (documented at https://developers.google.com/people/api/rest/v1/RequestMask).
It says that you'll need to include the requestMask parameter in your query, because you're doing a people.list query (i.e. using the connections GET endpoint). The requestMask parameter basically tells the API what fields to pull: person.emailAddresses tells it to pull the peoples' email addresses, person.emailAddresses,person.names tells it to pull their email addresses and names, etc.
GET https://people.googleapis.com/v1/people/me/connections?sortOrder=FIRST_NAME_ASCENDING&fields=connections(emailAddresses%2Cnames)&key={YOUR_API_KEY}
Try this and it will give you the emails. Make sure your contacts has emails.
You can get the profile emails from the Google People API, by making a request to https://people.googleapis.com/v1/people/me.
If you want non public emails, you will need to request the email or https://www.googleapis.com/auth/user.emails.read scope as specified in https://developers.google.com/people/v1/how-tos/authorizing#profile-scopes

Google Developer OAuth Consent: The supplied API key is not configured for use from this referrer

I'm trying to play around a little bit with the Google Calendar API but I can't create a OAuth ID ( as mentioned in this example: Google Calendar JS API.
I created a project, clicked Cerdentials and if you try to create an OAutho-client-Id you will be forwarded to the configure consent tab.
Here you have to enter your email address (is standard google account) and a project name. Then pressing save leads to an error:
{
"error": {
"code": 403,
"message": "The supplied API key is not configured for use from this referrer.",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/648364020234/apiui/credential"
}
]
}
]
}
}
The URL metioned in this JSON I can't access (no rights).
What can I do to get a simple oAuth ID?
Tried with several new projects, other naming of the consent projet name.
Also tried to create an API key which can be referred by all clients (empty field).
Any ideas anybody?

Categories

Resources