Similar to this question and solution: https://github.com/Azure/azure-iot-sdk-c/issues/1081
The caveat being I don't see how I can obtain the methodId necessary for delaying a response when using the convenience layer API. When the callback which was registered with IoTHubClient_SetDeviceMethodCallback() is called, setting payload response to NULL will result in no response being sent by SDK- I'd like to get the methodId in this callback to use later when response is ready.
I'd like to later call IoTHubClient_DeviceMethodResponse(), but how to obtain methodId necessary for this function?
Okay, I found the solution: need to register another callback to handle asynchronous direct methods. See: IoTHub_SetDeviceMethodCallbackEx()
https://learn.microsoft.com/en-us/azure/iot-hub/iot-c-sdk-ref/iothub-client-h/iothubclient-setdevicemethodcallback-ex
Related
I'm able to follow Twilio TaskRouter example to accept reservations:
import { Worker } from 'twilio-taskrouter'
const worker = new Worker(token);
worker.on("reservationCreated", async function (reservation) {
console.log('reserved', reservation)
await reservation.dequeue()
});
The incoming call reservation comes through and reaches the agent properly.
But I'm not clear how to actually answer the incoming call after this. The documentation says calling dequeue() will perform telephony but seems like there are more needs to be done to actually answer the call?
I also tried to create a Twilio Device. But based on my understanding, that requires a TwiML app, but I'm also not sure how to hook up the TwiML with the TaskRouter; nor I'm not sure I'm in the right path.
I actually figured it out by trying many diff SDK and code examples as the docs's not super clear.
Apparently we'd need to create a Device with its access token having the identity of the worker's contact_uri's client id.
"contact_uri":"client:a_worker_user_name"
When creating device access token:
const token = new AccessToken(
twilioAccountSid,
twilioApiKey,
twilioApiSecret,
{ identity: "a_worker_user_name" }
);
I'd like the following functionality with Twilio/Node: either
my server receives incoming call and the call rings on our custom client; at some point during the call (ideally can work before answering or after answering) or if no one answers on the client, the call is transferred to a webhook on a different server (my CRM provider) so the CRM can deal with it. OR
same as above, but the incoming call posts the incoming call request to both my server & my CRM webhook for the incoming call; I think this might not be possible though, not sure
I'm able to receive a Twilio call on my server without problem, and able to receive Twilio calls in my CRM without problem. However, when I tried to forward a call to the CRM after first receiving it on my custom server/client, it seems to always disconnect abrubtly. Pls help!
The code I'm using to update the call is below. The url works normally if sending the call directly to the CRM webhook. The CallSid is from my custom client from the incoming call
client.calls(req.body.CallSid)
.update({method: 'POST', url: 'https://crm.crmprovider.com/ctiapi/xml/cticall/twilio?authtoken=abc'})
Appreciate any help!
Think I figured out the proper way to do this. Should be using an "action" with "dial" and then checking "DialCallStatus" in the action endpoint and dealing with various statuses as appropriate. Sample code:
// On server, receive call. This is the url Twilio is
// set to post webhook to when call comes in
app.post('/incomingCall', (req, res) => {
const twiml = new VoiceResponse();
// Dial client first; after, call /callAction
// I believe this will call /callAction if call is unanswered for 10 seconds or after a completed call or if there's no client open
const dial = twiml.dial({timeout:10, action: '/callAction'});
const client = 'whateverClientName'
dial.client(client)
res.type('text/xml')
res.send(twiml.toString())
})
app.post('/callAction',(req,res)=>{
const twiml = new VoiceResponse();
// Can set below if for other things like if call not completed, answered, or cancelled
// In this example we say if call's not completed, route call to 3rd party site's webhook to further deal with the ongoing call
if(req.body.DialCallStatus!=='completed'){
twiml.redirect({method: 'POST'},'https://thirdpartywebhook.com/abc')}
else {twiml.hangup()}
res.type('text/xml')
res.send(twiml.toString())
})
I didn't find Twilio docs super straightforward on this so hopefully this helps someone in the future!
This is a really annoying issue. I am using a third party login in my application. When a user logins in through the third party, it redirects an api call to the server.
ex: /api/signin/github?code=test&state=test
For some strange reason this API call is getting fetched from the service worker instead on the server which handles the login logic.
ex:
Without seeing your service worker's fetch event handler, it's hard to say exactly what code is responsible for that.
In general, though, if there are URLs for which you want to tell the service worker never to respond to, you can just avoid calling event.respondWith(...) when they trigger a fetch. There are lots of ways to avoid doing that, but an early return is straightforward:
self.addEventListener('fetch', (event) => {
const url = new URL(event.request.url);
if (url.pathname === '/api/signin/github') {
// By returning without calling event.respondWith(),
// the request will be handled by the normal browser
// network stack.
return;
}
// Your fetch event response generation logic goes here.
event.respondWith(...);
});
I could not find any way to cancel a request using Siesta Framework. Is this possible, and how?
I found that there is a method cancel(), which should be called on the Request object. As documented, it is not guaranteed to really cancel the request if it is already started, but it will at least ignore the result and send you a completion/failure, which you can then handle accordingly.
Example:
let siestaRequest = MyAPI.profile.request(.post, json: ["foo": [1,2,3]])
// when needed, later
siestaRequest.cancel()
Since I'm kinda new to cloud code, I have the question mentioned above!
1) Do cloud code triggers, beforeSave - afterSave etc, need to call response.success and response.error when they are done?
2) If so, is it possible for the client to receive that response?
Edit: For the first question, I realised that it's necessary for the "before" triggers only...
The second question remains unanswered!
In a beforeSave() trigger, the response.sucess() is returned to the client like this.
It's only in case of error that it could be interesting to return a specific message (for a business validation before save for i.e)
So in your cloud code you could write :
Parse.Cloud.beforeSave("MyObject", function(request, response) {
//business validation then if fail :
response.error("there was an error blabla...");
}
});
Then the Client will receive a Parse Exception with the corresponding message