Getting the email id from the Outlook REST API when sending email - office365-restapi

I am trying to use the Microsoft Rest API to send emails on behalf of our users. When I create a message as a draft, I get back an ID that I can use in future requests for editing, deleting, viewing the full conversation (after it is sent), etc.
I do not want to save it as a draft since I have no reason to, I just want to send it directly. After it is sent, I would still like to view the full conversation. However, if I just send the email (using the /sendmail endpoint), I do not get that ID. Is there anyway to get it? Here is my request:
POST https://outlook.office.com/api/v2.0/Users/email/sendmail
{
"Message": {
"Subject": "Test",
"Importance": "Normal",
"ToRecipients": [{
"EmailAddress": {
"Address": "<email>",
"Name": "<name>"
}
}],
"Sender": {
"EmailAddress": {
"Address": "<email",
"Name": "<name>"
}
},
"Body": {
"ContentType": "HTML",
"Content": "<html>\\n<head>\\n <style>\\n p { color: red; }\\n </style> \\n</head>\\n<body>\\n <p>Test</p>\\n</body>\\n</html>\\n"
}
},
"SaveToSentItems": "true"
}
The HTTP response code is 202, the email sends, but the body is empty (no content, whatsoever).
I don't think this matters, since I can recreate this in Postman, but I am running this in Nodejs using the node-outlook package.

Emails in Exchange via REST and EWS are submitted for transport, but the actual send and subsequent save to the sent items folder are done async. This is why you don't get the id. Transport is who actually writes the email to the sent items folder, not REST.
If you really need to find the item after it has been saved to the sentItems folder, set something like the PR_SEARCH_KEY and then do a view of the sent items folder and seek to that search key value.
Also note when you save a draft, the id that you get back will be different than the id of the item in the sent items folder because the folder Id is part of the id of the item, so that id wouldn't help you anyways.

I don't know which rest api version are you using (i'm using v2.0) but i will try to explain this issue. Sorry for my english i advance.
You have 2 ways to reply a message: on the fly way or the complete way.
On the fly way
Its the easy way, just send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/reply
or
https://outlook.office.com/api/v2.0/me/messages/{message_id}/replyall
and with the body
{
"Comment": "This is your message in plain text or html code"
}
and thats all.
The problem with this methos that you can only send plain text or HTML, no attachments or anything else. If that's all you need this is your best option.
The complete way
If you need to send an attachment or perform any other action you need to perform these 3 steps:
1. Create a draft from the message you want to reply
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{message_id}/createreply
This will give you an json object save the "Id" property {draft_id} of this draft for later use.
2. Update the draft
Send a patch request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}
and with the body
{
"Body": {
"ContentType": "HTML or Text",
"Content": "Your response in plain text or html"
}
}
or any other parameter you want to change.
3. Send the draft
Send a post request to
https://outlook.office.com/api/v2.0/me/messages/{draft_id}/send
And thats it.
If you need more info abut this check https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations

Related

How to get the user id from Slack to bot service

I am creating a simple bot using Azure LUIS and this is my first one. I made some decent progress after doing some research and also now integrated with Slack as channel to test it.
The bot functionality is working fine, but I am looking to identify the user. So that I can personalize the bot conversation and also to pull the user specific information from his profile table.
Is there anyway, that I can get a UID or any reference ID of the slack user and so I can store that in my user table along with user profile?
So next time, when the user greets the bot, the bot can say "Hello, John." instead of justing say "Hello."
Thanks!
Yes. You can use the channelData object to get the ApiToken, and user values. For example, in C#, you could use turnContext.Activity.ChannelData to get those values in JSON:
{{
"SlackMessage": {
"token": "............",
"team_id": "<TEAM ID>",
"event": {
"type": "message",
"text": "thanks",
"user": "<USER WHO MESSAGED>",
"channel": "............",
"channel_type": "channel"
},
"type": "event_callback",
"event_id": ""............",
"event_time": 1553119134,
"authed_users": [
"............",
"<USER WHO MESSAGED>"
]
},
"ApiToken": "<ACTUAL TOKEN HERE>"
}}
Then, using those two pieces of information, you can then retrieve info from Slack.
https://slack.com/api/users.info?token=<ACTUAL TOKEN HERE>&user=<USER WHO MESSAGED>&pretty=1
And get a response that has the info you need:
{
"ok": true,
"user": {
"id": "<USER WHO MESSAGED>",
"team_id": "<TEAM ID>",
"real_name": "Dana V",
Ideally, you would would probably want to have bot user state setup and check that first, then if not there, then make the API call to Slack, then store in state. Therefore further requests don't need to go to Slack, but will just pull from the state store.
Basically, you could/should do this in the onTurn event. First, create your user state storage such as here.
Then you could check for that value and write to it if not populated. This example on simple prompts, might be helpful. You won't need to prompt for your user's name, as this example does, but does read/write username from state. You could still use dialogs, but you won't need them for the name prompting as you are doing that dynamically.
You can see here where username is being set and here where it is being retrieved. In this case, it is in the dialogs, but again; you would/could just do in the turn context (using logic to get and if not there, set).
I found the solution by priting the whole session object, which is having all the required informaiton. This could be same as mentioned by Dana above, but after debugging, this follwing made simple without making any changes.
var slackID = session.message.address.user.id
With above, I am able to identify the user.
Thanks.

POST request to Envelopes:create method

First of all - all code on PHP and JS.
I took all user data (sub, base_uri, account_id ) with that documentation https://developers.docusign.com/esign-rest-api/code-examples/config-and-auth at my site using cURL
Now I need send pdf file for that I generate at my site with that access for user sign like I have understood I need that https://developers.docusign.com/esign-rest-api/code-examples/signing-from-your-app and Envelopes: create https://developers.docusign.com/esign-rest-api/reference/Envelopes/Envelopes/create#examples
I send POST request to https://demo.docusign.net/restapi/v2/accounts/{accountId}/envelopes with accountId=account_id from user data, also I send json with user data and doc data in base64 in, but there is nothing, so I don't understand:
How should I call "create" method with POST to https://demo.docusign.net/restapi/v2/accounts/{accountId}/envelopes ?
What Id should I use in {accountId}?
At what format should I send the document for the sign?
Where can I find that doc after create?
Can you show me code example or show documentation with normal examples of POST request for that method.
If you are using a demo environment, I believe your authentication url is https://demo.docusign.net/restapi/v2/login_information. For production accounts, since the subdomain can be different you can find the correct baseUrl using a GET request to https://www.docusign.net/restapi/v2/login_information?api_password=true using Postman. This gives you the right baseUrl as well as your authentication information.
Here is how you can create a template using a base64 which is a POST call to {{baseUrl}}/templates
{
"documents": [
{
"documentBase64": "<insert encoded base64 here",
"documentId": "1",
"name": "blank1.pdf"
}
],
"envelopeTemplateDefinition": {}
}
Also, if you need to generate more requests make sure you check out the Postman collection that contains different examples as Sebastian mentioned too:
DocuSign Postman Collection

Docusign Connect Envelope status when print and upload is used

I have a connect endpoint created and I am trying to differentiate between a digitally signed envelope, and one where the document was downloaded and reuploaded using the Print and Sign feature.
Currently it seems that I get onSigningComplete event in both cases mentioned above when the document is submitted.
I also see that the status of the envelope gets set to Completed when I receive the connect response at my end point.
My questions are as follows:
Is this the expected behavior, or am I missing something?
Is there some flag in the envelope that indicates that a document was downloaded, signed and uploaded vs. signed digitally? If yes, how do I get that flag in my connect end point?
You can refer to https://docs.docusign.com/esign/restapi/Envelopes/Envelopes/listAuditEvents/
and call endpoint
GET /v2/accounts/{accountId}/envelopes/{envelopeId}/audit_events
to get list of audit events happened for that envelope, for eg: it will show you list of events for Print and Sign like:
a. {
"name": "Action",
"value": "Printable Copy Delivered"
},
{
"name": "Message",
"value": "Signer1 received a printable copy of the envelope"
}
b. {
"name": "Action",
"value": "Uploaded Attachment"
},
{
"name": "Message",
"value": "Signer3 uploaded a file that contains paper with hand signature"
}
These audit events will show if document was download, signed & uploaded vs signed digitally

How can I request the user's location in API.ai?

I'm creating an agent using api.ai and using a PHP script as a webhook. The documentation doesn't make it clear on how to do it, but I'm wanting to request permission to the user's coarse location so they won't have to provide their location for requests.
I've tried echo-ing the JSON they mention, and putting it in as a custom payload for the default welcome intent, but neither of those seem to prompt me for permission to use my location.
How do I ask a user for permission to get their location?
EDIT: If I set my PHP script to respond to intent.welcome with the following JSON:
{
"data": {
"google": {
"expectUserResponse": true,
"systemIntent": {
"intent": "actions.intent.PERMISSION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"optContext": "To provide an accurate experience, ",
"permissions": ["DEVICE_PRECISE_LOCATION"]
}
}
}
}
}
The app asks me "To provide an accurate experience, , I'll just need to get your street address from Google. Is that ok?"
However if I say "yes", then the app keeps asking things like "Sorry, could you say that again?", so I can't actually get it to do anything.
You need to create a new Intent with the Event set to actions_intent_PERMISSION. (See image below.)
When this Event is triggered, your webhook will be called with the JSON originalRequest.data.device.location field in the request body populated with the location information you've requested.

Not able to rename document of Draft envelope

Our application creates a draft envelope from template using docusign rest API. Based on the user input application renaming the document and send envelope for signing.
We are using API PUT "docusignUrl/envelopes/{envelopeId}/documents" to rename the documents of a draft envelope from past 10 months. It was working till yesterday. All of sudden today it is not renaming the document. It is keeping document name as template name itself.
Can somebody please help me to rename the document. I am using demo.docusign.net
Following are the request and response contents.
Url: https://demo.docusign.net/restapi/v2/accounts/1234/envelopes/a499c33a-94c6-46e1-a0f2-bf5cd368529b/documents
Request body:
{"documents":[
{"name":"150821183100_Order-Sign_companyc_P",
"documentId":"1",
"order":"1",
"pages":"1",
"type":"content",
"uri":"/envelopes/a499c33a-94c6-46e1-a0f2-bf5cd368529b/documents/1"
}]
}
Response Body:
{
"envelopeId": "a499c33a-94c6-46e1-a0f2-bf5cd368529b",
"envelopeDocuments": [
{
"documentId": "1",
"name": "SOMA_Sign_OrderManagement.pdf",
"uri": "/envelopes/a499c33a-94c6-46e1-a0f2-bf5cd368529b/documents/1",
"order": "1"
}
]
}
Your previous behavior is the desired behavior.
This is a bug that is being looked into by DocuSign, I'll update this answer if I get any additional information.
UPDATE: The issue has been resolved and is working as intended in Demo once again.

Resources