Surveymonkey: call webhook when survey is completed - surveymonkey

I would like to receive webhook calls to my own service when a survey has been completed. I do not want to poll surveymonkey for results. I noticed there is some obscure documentation here: http://help.surveymonkey.com/articles/en_US/kb/WebHook-PUT but it is not useful.
Has anyone had any experience with this?

You can setup a webhook with SurveyMonkey API v3. To create a webhook, you would make a request like:
POST /v3/webhooks
{
"name": "My Survey Completed Webhook",
"event_type": "response_completed",
"object_type": "survey",
"object_ids": ["<survey_id1>", "<survey_id2>" ...],
"subscription_url": "https://example.com/surveys_responses",
}
Now every time a survey is completed, a notification will be made to the subscription_url specified when creating the webhook. The notification will be a skinny payload with the response_id which you can use to fetch responses:
GET /v3/surveys/{id}/responses/{id}

Related

Send message to self-Chat in Microsoft Teams using Graph API

I'm trying to send a message to my self-Chat in Microsoft Teams through a Graph API call but can't find the ID of this specific chat. For the record, this type of chat was introduced to Teams in June, 2022.
By reading the Graph API documentation, it's possible to list all chats available for a specific user using the following API call (in this case, myself):
[GET] https://graph.microsoft.com/beta/me/chats/
Yet, I can't seem to find my self-chat in there. The chat itself is already created since I wrote messages in it but it doesn't appear in the call response.
I've tried to filter the results by most recent results, by filtering on my own name or by filtering by ChatType, but it was still missing.
Is anyone aware of a way to get the ID of a user self-chat in Microsoft Teams?
Thanks!
Self chat is a special kind, You can use this endpoint to communicate with it:
https://graph.microsoft.com/v1.0/me/chats/48:notes/messages
Hope that helps :)
Answering harrywyn's question regarding the pop up notification, you can set it as unread the same as any chat like this:
EndPoint = f'https://graph.microsoft.com/v1.0/chats/48:notes/markChatUnreadForUser'
update_chat = {
"user": {
"id" : uid,
"tenantId": TENANT_ID
}
}
resp = requests.post(EndPoint, headers=headers, verify=False, json=update_chat)

Microsoft teams messaging extension inconsistently sending a valid conversation ID to use in a graph call

I am developing a MSTeams application, and inside I use a messaging extension. Upon opening the extension, a request is fired over to my message handler, which I use an azure function to handle. Alongside the request is a payload, with details about the context (in this case the conversation or chat) of where the messaging extension was opened from.
Now, I've built up a graph URL with the conversation ID from the payload:
const id = context.req.body.conversation.id
const graphEndpoint = encodeURIComponent(`https://graph.microsoft.com/beta/me/chats/${id}/members`)
I authenticate a user by calling microsoftTeams.authentication.authenticate({...}) before I make the call, and use the token in the request.
Sometimes, this call will succeed, and return the information I want. However, the other times it will fail with a 400, telling me I had a bad request, despite it being a GET request with no body.
I notice in bad requests, that the conversation ID doesn't trail with #thread.v2 or #unq.gbl.spaces etc. I have no clue why this is so inconsistent, or if it's my fault. Any help would be appreciated.
EDIT: I have also seen that the issue only occurs when the id starts with a:, and succeeds when it starts with 19:. However, the context in which I open the messaging extension is the same each time: In a 1:1 / User:User chat.
I have previously implemented installing the bot in the conversation to get this information, but this method is very undesirable. Perhaps a side point - it seems that the conversations where I have previously installed the bot seem to return the 19: id, and everything else a:.
Here's an example of the 400 response:
{
"error": {
"code": "BadRequest",
"message": "Bad Request",
"innerError": {
"date": "2021-01-25T09:43:26",
"request-id": "3bb55aa2-e694-4c80-952c-88842f482dc1",
"client-request-id": "3bb55aa2-e694-4c80-952c-88842f482dc1"
}
}
}
The conversation id you received in the turn-context is not the chat-id. The conversation id is different from conversation id. Conversation id the id between bot and the user and chat id the id of the chat. Both are different. You cannot use conversation id to call the graph API. Please use the chat id to call graph API. You can get the chat id using list chats API.

How to handle payment success in stripe?

After a user visits the payments page and successfully makes a payment, Stripe will redirect the customer to whatever url is provided to success_url
Stripe.api_key = 'sk_test_51HYHSFGtUKse83O9J4QeAib3cp8sHzGaOQRrn7sba92Hd8dCHE3AIHe5ModevMK7TVAUCyJU0ADSwIUoX00qxZmBI9r'
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
name: 'Kavholm rental',
amount: 1000,
currency: 'aud',
quantity: 1,
}],
payment_intent_data: {
application_fee_amount: 123,
transfer_data: {
destination: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
},
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/failure',
})
Now the app/platform must arrange 'fulfillment':
After the payment is completed, you’ll need to handle any fulfillment necessary on your end. A home-rental company that requires payment upfront, for instance, would connect the homeowner with the renter after a successful payment.
Also (bold from me):
Do not rely on the redirect to the success_url param alone for fulfilling purchases as:
Malicious users could directly access the success_url without paying and gain access to your goods or services.
Customers may not always reach the success_url after a successful payment. It is possible they close their browser tab before the redirect occurs.
Up to this point, everything is very well explained in the stripe docs and very understandable.
But I want to know: what is the best thing to do next, noting that:
a payment may not go through immediately, so simply loading the success_url might be premature
a webhook can be (easily) configured to listen for events, however if the success_url is loaded even 1 second before the webhook receives a success message, then it won't know that the payment went through successfully (so, for example, displaying "Congrats, your product will be shipped!" message could be presumptuous
Question
So, finally, the question: what is best practice for the flow on from success_url? I am just confused as to what is the best pattern..
Ideas
Here are some things I've considered:
Upon routing to success_url, simply use sleep(5) and then check the webhook in the controller for the success_url so it takes 5 extra seconds to load giving the webhook a chance to receive incoming events, so you can display either "Congrats your product will be shipped!" or "Oh, no, something went wrong with your payment, please try again or contact your bank".
Routing directly to success_url, but then having a message saying "please refresh in a moment" (then listening for a webhook indicating the payment was successful, and then conditionally showing the "Congrats your product will be shipped!" message)
The documentation for fulfilling orders has this in an info box under the code snippet:
Your webhook endpoint redirects your customer to the success_url when you acknowledge you received the event. In scenarios where your endpoint is down or the event isn’t acknowledged properly, your handler redirects the customer to the success_url 10 seconds after a successful payment.
The event referenced above is the checkout.session.completed event sent to your webhook endpoint. The delay is designed to let you confirm the payment is successful and customize the success page based on the result of the Checkout Session's outcome.
In other words, Checkout won't send someone to your success_url until you've responded to the checkout.session.completed event request from your webhook endpoint with a successful (2xx) response, giving you time to customize the success page based on the outcome.
You can, for example, default to a "your payment is being processed" success page, but if you confirm the Checkout Session and payment succeeded after receiving the checkout.session.completed event, you can instead change the page to read "congrats your product will be shipped".
This approach means you can reliably present a success page that always has displays accurate information.

Can I Update Subscription Properties via REST API using PATCH method?

I know that when you want to renew your subscription I need to call subscriptions endpoint with payload which tells new expiration date or nothing, to get maximum 3 days.
// endpoint
me/subscriptions($subscriptionId)
// payload
{
"#odata.type": "#Microsoft.OutlookServices.PushSubscription"
}
What I want to do now, is to update NotificationURL property of that subscription.
I figured it should work like this using PATCH method:
// endpoint
me/subscriptions($subscriptionId)
// payload
{
"#odata.type": "#Microsoft.OutlookServices.PushSubscription",
"NotificationURL": "https://app.domain.com/notifications"
}
But when I try to do this I only get following errors:
code: ErrorInvalidParameter
message: Notification URL 'https://oldapp.domain.com/notifications?validationtoken=[someHashCode]' verification failed 'System.Net.WebException: The remote server returned an error: (404) Not Found.
Well, of course it fails and gives 404, because it's trying to connect old NotificationURL. It looks like, it's just trying to renew subcription instead of only updating NotificationURL property of that subscription.
I know I can handle this manually in few ways for example by creating new subscriptions, but I want to make this to work automatically everytime my server boots. And it feels like a good idea to just update the NotificationURL instead of unsubscribing from all notificaitons and creating new ones.
Any help would be appreciated!

Received webhook notification but with empty data in servicem8

I can successfully register the webhook in serviceM8. By list the webhook subscriptions i got the result like this
[{"object":"job","callback_url":"http://ABC.XYZ/oauth/webhook/m8","fields":["active","payment_processed","uuid","company_uuid"],"active":true}]
But when i try to create new job & approve the job in servicem8, i received the notification from serviceM8 but the data in body is all empty like :
body: { '{"object":"JOB","entry":': { '"payment_processed"': '' } }
Am i missing something in webhook setup ???
Webhook notifications will not include the data record itself, only a reference to the record that has been changed/updated.
Your callback url should be receiving a JSON body similar to the example here (under Handling Webhooks):
http://developer.servicem8.com/docs/platform-services/webhooks/
Once you receive the notification, you will need to request the updated record using the supplied resource_url.

Resources