Get the URI the MPNS to returns to the push client when creating a notification channel Windows Phone 7 - client-server

/*Get the URI that the Microsoft Push Notification Service returns to the Push Client when creating a notification channel.
Normally, a web service would listen for URIs coming from the web client and maintain a list of URIs to send
notifications out to. */
string subscriptionUri = TextBoxUri.Text.ToString();
Further information on how the pushclient would then sync the URI with a webservice lacks in the description given on MSDN.
So, does anyone know how to make my app send its URI to the MPNS using the push notification client of the Windows Phone, iso having to manually copy-paste them into my web application?
Greetz GP

See MSDN Windows Phone Code Samples at:
http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
The following code snippet from the 'sdkToastNotificationCS' example show a possible location to store the uri or send to your webservice:
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
e.ChannelUri.ToString()));
// Instead of showing the URI in a message box, POST to your web service
});
}
Execute an HTTP POST request to send the URI and an identifier for you push user. Receive this POST data on your web service and store the user/URI so you can push notifications to that user from your web service.

You just need an endpoint on your server that the app can send the PNS uri (and any other relevant information) to.

Related

image appears in dialogflow chatbot but not shown in whatsapp chatbot and making twilio error

see update: Partial Solution
I'm using dailogflow and twilio to make whatsapp chatbot.
Text messages appears normally in both dialogflow and whatsapp.
Images appears only in dialogflow chatbot, but it is not working in whatsapp chatbot and makes error in twilio
This is the part of code which I'm adding to Inline Editor of DialogFlow fulfillment:
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'http://examplesitelink.com/image_name.png',
})
below the error message which I receive in twilio
MESSAGE
The URI scheme, of the URI null, must be equal (ignoring case) to 'http', 'https', 'ws', or 'wss'
......
HTTP retrieval failure
......
Possible Causes
Web server returned a 4xx or 5xx HTTP response to Twilio
Misconfigured Web Server
Network disruptions between Twilio and your web server
No Content-Type header attached to response
Content-Type doesn't match actual content, e.g. an MP3 file that is being served with Content-Type: audio/x-wav, instead of Content-Type: audio/mpeg
Is there anything I can do to solve this problem?
Partial Solution
Below a partial solution
I became able to send images to whats app via dialogflow fulfillment
First, in the 'package.json' I added twilio in dependencies, "twilio": "3.37.1" (check the latest version on npm twilio)
Second I added below code to send an image to whatsapp using its url, and it works
const client = require('twilio')('YOUR_ACCOUNT_SID', 'YOUR_AUTH_TOKEN'); /* change YOUR_ACCOUNT_SID and YOUR_AUTH_TOKEN to your own twilio account data */
client.messages
.create({
to: 'whatsapp:+13233633791', /* change it to your the number which you want to send the image to*/
from: 'whatsapp:+18007778888', /* change it to your the number which twilio sandbox provide, you can find it here: https://www.twilio.com/console/sms/whatsapp/sandbox */
body: "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
mediaUrl: 'https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG',
})
.then((message) => console.log(message.sid));
the problem now is:
In previous code, to is required, which means I have to specify the number which I want to send the image to, that looks odd, but the code will not work if I didn't specify to.
What I need to know is, how can I change: to: 'whatsapp:+13233633791', to any code can send the message to the current user who use whatsapp
I have also faced the same problem of not being able to send the media messages to any user that is using the chatbot currently. I found the solution to that in a youtube video, in which they have extracted the receiver mobile no. from the request object like below -
const data = request.body.originalDetectIntentRequest.payload;
const To = data.From;
const From = data.To;
Here the request object is the one you get when you create your dialogflow agent using the code below 'req' here-
app.post("/", express.json(), (req, res) => {
-------------------
-------------------
function handler() {
----------
}
intentMap.set("intent", handler);
}

How do I retrieve the sender number when using Twilio's messaging services with Copilot enabled?

I have a Twilio messaging service with Copilot and the sticky sender feature enabled.
I would like to view the phone number that Copilot assigns to my recipients when I send them a message.
With the Ruby client, I get a MessageContext object when I send a message, but it only has the
messaging service SID - the from method returns nil.
Currently, this is how I'm sending messages:
def send(from, to, message)
client = Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
client.api.account.messages.create(
body: message,
messaging_service_sid: from,
to: to,
status_callback: BASE_URL + '/sms_status/status',
)
end
Twilio developer evangelist here.
I'm not sure, but you might not have the phone number at the time you make the API request using a messaging service. This request really just queues up the message to be sent.
I would check the message object once it has been sent. You have a status callback URL setup, so you should be able to either inspect the parameters sent to that URL or look up the message from the API using its SID and then get the number that was used.

Twilio client: Outbound call isn't showing agent/caller name in 'From' field on call logs

I'm making an outbound call from my Twilio client to make outbound web browser calls. The calls are successfuly made and are fine, but...
Unfortunately I'm unable to see the agent/client name in your logs. I am currently using the agent/client name of 'Andy' but in Twilio's call logs it's showing the 'From' field as anonymous.
I have made a few changes to the JavaScript SDK and have added the following ''//CLIENT NAME clientName: 'Andy'' in the 'params' variable but this hasn't made a difference and the from field is still showing up as Anonymous in Twilio's call logs when I make an outbound call using the browser client.
How do I make this work? :(
Here is my code:
// Bind button to make call
document.getElementById('button-call').onclick = function () {
// get the phone number to connect the call to
var params = {
//CLIENT NAME
clientName: 'Andy',
//PARAMETERS THAT WILL BE SENT THROUGH TO TWILIO
To: document.getElementById('customer-number').value,
//THIS IS CUSTOMER CALLER ID WE'RE PASSING TO THE OUTGOING TWIML AS THE CALLER ID TO USE FOR OUTGOING CALL
CallerID: document.getElementById('source-number').value
};
console.log('Calling ' + params.To + '...');
Twilio.Device.connect(params);
};
Twilio developer evangelist here.
The parameters you pass into Twilio.Device.connect are not recorded by Twilio, but they are sent on as parameters to the URL you set as your application URL.
Client names are actually only required for incoming calls that are routed to a client. If you were to setup a client for outgoing calls only you need not setup a name. As such, client names are not captured by Twilio in the call logs.
If you need to track which clients are making calls you can do so within your own application by reading the clientName that you set in Twilio.Device.connect from the webhook parameters and associating it with the CallSid (also available in the webhook parameters).

Braintree ios + java transaction API returns 403

Just started the project. The client side app is the Braintree demo app. I modified it to point to my server running on localhost
Here is what I'm doing.
ios app makes an request to server to get a token
server uses method below to get a token from Braintree and sends back to server
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX,
merchantAccountId,
".........",
"............."
);
String token = gateway.clientToken().generate(); // Braintree did return a token
ios demo app creates a nonce with the drop-in view
ios demo app sends the nonce to the server
// nonce sends to server 71a89c9d-6ca7-4804-a895-b0e7564425c6
server calls Braintree API with code below
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal(19.0f))
.merchantAccountId(merchantAccountId)
.paymentMethodNonce(nonce)
.options()
.submitForSettlement(true)
.done()
.channel("MyShoppingCartProvider");
Result<Transaction> result = gateway.transaction().sale(request);
return result;
The last step got 403 com.braintreegateway.exceptions.AuthorizationException exception from Braintree. The xml from the error stream is Unauthorized. The input stream from Braintree says "Server returned HTTP response code: 403 for URL: https://api.sandbox.braintreegateway.com:443/merchants/vb38crtnzn77b9ys/transactions"
Thanks for the help
It turns out that there are two IDs. One is merchantId and the other merchantAccountId. The server sends back the merchantId back to client. And later for charging, use merchantAccountId.

WP7 Push Notification 404 response

My push client sends the URI to my web service, by using the URI, from my web service, I am able to send toast notification to my app installed on Emulator. But if I use the device URI and try to send a message to the device from web service, I get 404 as response. Can anyone tell me What the issue could be ?
Assuming you aren't having any problems receiving and storing the URL your physical device sends to your service, and that you are sending messages to this URL, the only thing I can think of is something I noticed during testing. On occasion, if a malformed message is sent to the URL, it appears to go into a faulted state and any subsequent message (even if well-formed) sent to the service returns a 404.
I don't know if this is expected behaviour or a bug - I resolved it by fixing the malformed messages I was trying to send, and refreshing the channel from the device.

Resources