Get the Message Id or thread Id immediately after sent gmail - google-chrome-extension

Can I get the message id or thread id immediately after sent gmail using google script or gmail API.?

Yes you can.
Acording to documentation, when you send a message using Users.messages.send method of the API, the response will be a messages.resource which includes the message Id and the thread Id of the message just sent.

Related

How to send a response to dialogflow later

I am using dialogflow by google to create a bot.
When my user ask my bot for a report with several parameters, I need to create the report and send him the link to download it.
The report is created in about 1 minute. When I send the response (JSON(fulfillmentText = "my url")) of the POST request of my webhook, dialogflow send me an error : time out.
So I need to send immediately the message "Please wait..." and then, when the report is created, send to my user a new message with the url of my report.
I am trying to use the API V2 but I cannot find in the documentation a way to send a message to a user when the POST request is already done.
This is not possible, the interactions with Dialogflow agents are intended to be conversational and must be initiated by the user. The timeout for your fulfillments response is five seconds.
It would probably be a better user experience anyway if you get an email address from the user and send them the link there, either by asking for it with the #sys.email system entity (be aware of privacy issues though) or by using account linking.

Emails/drafts sent via Gmail REST API can't be opened in the new Gmail UI

When sending drafts via the Gmail REST API, the message in the "Sent Mail" folder can't be opened by the sender in the new Gmail UI. You get the error message "The conversation that you requested could not be loaded.".
The message on the recipient side can be opened without problem though, new UI or not.
Reverting to the old/classic Gmail UI allows the sender to open the sent message.
Steps to reproduce:
Compose a draft in Gmail (new or old UI doesn't matter)
Find the draft ID via GET https://www.googleapis.com/gmail/v1/users/me/drafts
Send the draft via POST https://www.googleapis.com/gmail/v1/users/me/drafts/send with body {"id": "<draftId>"}
Go back to Gmail and switch to the new Gmail UI, then attempt to open the recently sent draft in the Sent folder. Attempting to open the message will fail.
Revert to the old/classic Gmail UI and open the recently sent draft in the Sent folder. You will be able to open the message without issues.
The recipient will be able to open the message without issues, using either the new or old UI.
UPDATE
When the broken sent email receives a reply, it seems to get 'fixed' and the sender can now open the sent email from the new Gmail UI. This seems to suggest that the REST API is missing something that gets fixed once the thread is updated by other means?
The error message in the browser console when attempting to open the broken sent message:
Error: Ppa No message loaded when we received the DETAILED_CONVERSATION_MESSAGES_LOADED event.
I can't reproduce this. Note that in the reproduction steps #2 is unnecessary. Instead, the result of drafts.create() in #1 should be analyzed, the id of the new draft message is present there.
Also worth noting, Draft IDs are not the same as Message IDs. The response of drafts.create() and drafts.update() will be a Draft ID while the result of drafts.send() will be the message ID. When viewing the sent message in Gmail UI make sure you are using the message ID.

Can I get Dialogflow send a request to my webhook when I trigger an event?

I want to trigger an intent/event in Dialogflow [from my webhook/server] and have Dialogflow send a request to my /webhook instead of just responding to the POST request that I made which triggered the event. Is that possible? I want to send the user a message based on their input in our web application, but the response types could vary greatly so I can't define the message and payload in the DF web panel.
edit: [in brackets]
Yes, Dialogflow can send information to a webhook - it refers to this as fulfillment.
Keep in mind that the JSON sent by Dialogflow will be in its format, not yours, and it expects a reply in its format as well. This reply will include the message to be sent back to the user (the response to the original POST request).

How to get inline keyboard for a previously sent message?

Consider the following sequence:
A Telegram bot sends a Message with an inline keyboard with InlineKeyboardMarkup to a specific User
When the user hits one of the buttons of an InlineKeyboardMarkup, bot receives a response with a CallbackQuery
CallbackQuery contains a message object, which represents the original message, which was sent in step 1, but as far as I can see in API docs, Message does not contain any information about InlineKeyboardMarkup or reply_markup.
So is it possible to get InlineKeyboardMarkup of the originally sent Message?
If there is no way of getting it, are there any workarounds in this case?
Update 1 June 2019
Recently Telegram Bot API developers added a new field reply_markup of type InlineKeyboardMarkup to a Message object.
So now you can get previously sent keyboard like that: Update.CallbackQuery.Message.ReplyMarkup

How to associate sendgrid webhook sg_message_id to sent mail?

Sendgrid webhook has sg_message_id
But the response of Web API v2 when sending mail doesn't have sg_message_id.
In fact, there is only message showing only success or failed.
So, how do i associate between sent mail and the webhook callback?
I have check the past questions in SO but it doesn't provide be the solution for this.
Thank you.
You can use unique arguments. Take your unique ID (like primary key) and give it to sendgrid API during sending email. You will get it back in the event webhook.
https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html
EDIT: The best practice seems to be using custom arguments (see documentation). Which is not apparent from the documentation (as of today).
In Web API v3, the response includes a special header X-Message-Id (see https://sendgrid.com/docs/Glossary/x_message_id.html).
This can be later matched with sg_message_id in webhook: https://sendgrid.com/docs/Glossary/message_id.html
The documentation does not make it clear, but the X-Message-Id header is actually not equal to sg_message_id, but it is a prefix of sg_message_id.
For example:
X-Message-Id = "MUvGg3V1ThOu3oe8eRqFrA"
sg_message_id = "MUvGg3V1ThOu3oe8eRqFrA.filter0001p2iad2-21183-5AF0BD9B-E.0"
The Web APIv2 call that sends out the email only responds with a {message :"success"} answer indeed, but the sg_message_id is not generated at that point. The API call answer simply acknowledges that the email was sent to SendGrid for processing.
The email is sent to SendGrid, and there it receives the sg_message_id value that is provided through the Event Webhook posts.

Resources