I'm getting notifications using Pub/Sub, but the messageId I get is not the messageId to see the email content, how can I get this messageId?
I get this data on my endpoint
{
message:
{
data:"eyJlbWFpbEFkZHJlc3MiOiAidXNlckBleGFtcGxlLmNXXXXXX,
"messageId": "2070443601311540",
"publishTime": "2021-02-26T19:13:55.749Z",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
The pub/sub messageId has nothing to do with the gmail messageId.
I need to get the messageId from gmail whenever a new email is received in my inbox.
You can get the historyId from the data part after base64 decoding it.
By history id you can get all the messages that are being affected in that history record.
Save this historyId in your local DB or Json file.
next time whenever you receive a new notification from gmail pub/sub you have to call user_history->list by providing the previous history_id that you saved in DB. And save that latest historyId in your DB for future.
call users_history->listUsersHistory(), to get the history object.
The history object also have messagesAdded, messagesDeleted, labelsAdded, labeslRemoved Collection. In general messages collection you may get duplicate messages try being specific.
call usersMessages->get(), to get the specific message.
$service = new Google_Service_Gmail($client);
$response = $service->users_history->listUsersHistory('me', ['startHistoryId' => $historyId]);
$historyList = $response->getHistory();
foreach ($historyList as $history) {
foreach ($history->messages as $message) {
$message = $service->users_messages->get('me', $message->id);
}
}
Note: if you try to get history record from the latest history Id (received in response) you will get nothing because that is the new history Id which contains nothing now.
you have to get the history list starting from the previous history Id
for more details, read these
https://developers.google.com/gmail/api/reference/rest/v1/users.history/list
https://medium.com/#eagnir/understanding-gmails-push-notifications-via-google-cloud-pub-sub-3a002f9350ef
Related
Hi I'm tying to make a say command that sends attachments that was sent while using the command for example someone uses !say while attaching 3 attachment and it sends the 3 attachments last time I tried to do it I could only get the first attachment but I want to get all the attachments that was attached with the message
If you want to get the files or images that are attached to a message, you can access the attachments property of the message object. This will return a Collection of attachments that you can iterate through and attach to your new message.
e.g.
client.on("message", message => {
if (message.attachments) {
let attachments = message.attachments;
for (let file of attachments) {
message.channel.send({files: [file]});
}
}
})
You can get more information about this in the Discord.js documentation.
I'm not getting any webhook notifications for bad email addresses that respond back with unknown mail recipients. I do get a notification email for this but no webhook notification.
envelope code setup
{
var envelopeDefinition = new EnvelopeDefinition()
{
EmailSubject = request.EmailSubject,
EventNotification = new EventNotification()
{
RequireAcknowledgment = "true",
Url = config.Value.EnvelopeEventUrl,
EnvelopeEvents = new List<EnvelopeEvent>
{
//new EnvelopeEvent("Delivered"),
new EnvelopeEvent(EnvelopeEventStatusCode: "Voided"),
new EnvelopeEvent(EnvelopeEventStatusCode: "Declined"),
new EnvelopeEvent(EnvelopeEventStatusCode: "Completed", true.ToString()),
},
RecipientEvents = new List<RecipientEvent>
{
new RecipientEvent(RecipientEventStatusCode:"AuthenticationFailed"),
new RecipientEvent(RecipientEventStatusCode:"AutoResponded"),
new RecipientEvent(RecipientEventStatusCode:"Delivered"),
new RecipientEvent(RecipientEventStatusCode:"Declined"),
new RecipientEvent(RecipientEventStatusCode:"Completed"),
}
},
TemplateId = request.TemplateId,
Status = "Sent",
EmailSettings = new EmailSettings(ReplyEmailAddressOverride: "Reply#xxxxFinance.com.au", ReplyEmailNameOverride: "John Smith"),
};
Sadly this DocuSign link is broken
See Using Webhooks to Track Envelope Status for details
Also I can't login to support using my DocuSign Demo account (Sandbox account), not sure why, so can't log a support ticket!
So, first of - the link is not broken. Not sure what you meant by that.
Second, the issue here may be that sometimes remote servers do not respond back very quickly to let you know an email bounced.
You could try a different strategy where you look for the positive message (that the status of the recipient changed to indicate the email message was sent succsefully) and if you don't get that within say, 5 min - you assume it bounced (but that's on you, sometimes it is just delayed a lot).
See, you subscribed to five different recipient events. The one called "Delivered" is the positive (or opposite) of "AutoResponded" (which may also mean that the person had their Out-Of-Office message on). So, by checking if it was delivered, you can tell when the message got there safely, but not when it bounced for sure.
Using Discord.js in an Express/Node.js app, I'm trying to build a bot that grabs external data periodically and updates Discord with an embed msg containing some elements of that data. I'm trying to add a feature that will check if that data was deleted from the external source(no longer existing upon the next grab), then delete the specific msg in Discord that contains that data that was sent.
Some of the msgs posted in Discord may have duplicate data items, so I want to delete by specific msg ID, but it seems that msg ID is assigned when posted to Discord.
Is there a way to programmatically grab or return this msg ID when sending from Discord.js, rather than manually copy/pasting the msg ID from the Discord GUI? In other words, I need my bot to know which message to delete if it sees that msg's source data is no longer being grabbed.
// FOR-LOOP TO POST DATA TO DISCORD
// see if those IDs are found in persistent array
for (var i = 0; i < newIDs.length; i++) {
if (currentIDs.indexOf(newIDs[i]) == -1) {
currentIDs.push(newIDs[i]); // add to persistent array
TD.getTicket(33, newIDs[i]) // get ticket object
.then(ticket => { postDiscord(ticket); }) // post to DISCORD!
}
}
// if an ID in the persistent array is not in temp array,
// delete from persistent array & existing DISCORD msg.
// message.delete() - need message ID to get msg object...
// var msg = channel.fetchMessage(messageID) ?
Let me refer you to:
https://discord.js.org/#/docs/main/stable/class/Message
Assuming you are using async/await, you would have something like:
async () => {
let message = await channel.send(some message);
//now you can grab the ID from it like
console.log(message.id)
}
If you are going to use .then for promises, it is the same idea:
channel.send(some message)
.then(message => {
console.log(message.id)
});
ID is a property of messages, and you will only get the ID after you receive a response from the Discord API. This means you have to handle them asynchronously.
What is a correct way to synchronize Twilio chat consumption horizon and send an email notification with a list of new messages from our own server?
I can use kind of pre-hooks / post-hooks for new messages, but I don't want to keep every message and its reading status in my database.
Is there a smarter way to set up notifications on my server?
Twilio developer evangelist here.
You wouldn't need to store all of this. You can just use the REST API to get all of this information.
What you need to do is store your user's Channel Member Sid. You can then make a call to the Member resource and get their last_consumed_message_index.
With the index, which is an integer representing index of the last message the member has read within the channel, you can then call on the Message resource to list all the messages since that index. In Node, that would be so
service
.channels(CHANNEL_SID)
.members(MEMBER_SID)
.fetch()
.then(member => {
const lastConsumedMessageIndex = member.lastConsumedMessageIndex;
return service.channels(CHANNEL_SID).messages.list({
pageSize: lastConsumedMessageIndex,
limit: lastConsumedMessageIndex
});
})
.then(messages => {
console.log(messages);
// do something with unread messages
})
.catch(error => {
console.error(error);
});
Let me know if that helps at all.
Why i got Customer id and invoice id cus_0000000000000 and in_0000000000000 like these? in stripe webhook response.
I am checking my events and response in my account in this i got response 200 ok,but got customer id and invoice id got like these.why? i am checking send test webhook event at this i got response like these.
public function actionStripeHook() {
if (Yii::app()->request->isPostRequest) {
try {
$postdata = file_get_contents("php://input");
$event = json_decode($postdata);
switch ($event->type) {
case 'invoice.payment_succeeded':
Yii::log('', 'trace', 'stripe');
Yii::log('==================================', 'trace', 'stripe');
Yii::log('==== Event (' . $event->type . ') ====', 'trace', 'stripe');
Yii::log('==================================', 'trace', 'stripe');
$customer_id = $event->data->object->customer;
$customer = Stripe_Customer::retrieve($customer_id);
$invoice = Stripe_Invoice::retrieve($event->data->object->id);
}
What's Wrong in my code Its my action in Webhook endpoint in stripe,I got event type invoice.payment_succeeeed its coming from that case,but cant get customer id and invoice id correctly in my Response.why?
Nothing is wrong with your code -- the "Send test webhook" button sends a correctly formatted JSON event, but all the resources IDs are xxx_000000000.
The "Send test webhook" button is mostly useful for testing connectivity between Stripe and your webhook handler. If you want to test actual functionality, you should generate the events "organically", i.e. by sending the requests that will trigger the events you want.
For instance, to generate an invoice.payment_succeeded event, you should:
create a customer, with a valid card (e.g. 4242424242424242)
create a subscription for this customer
Upon creating the subscription, an invoice will be created and payment will be immediately attempted. If the payment is successful, then an invoice.payment_succeeded event will be emitted (with valid IDs).