Xamarin Push Notification, Handling the remote notification once the app becomes active - xamarin.ios

I know how to send notifications to my iOS devices through PushSharp. However, once I do and the app is inactive, I am looking to find a way to handle the push notification once the app becomes active again.
In other words, I want to be able to see what item they clicked on and be able to show data relevant to that.
Here is a link for reference, it does what I am asking for, but only when the app is active.
http://roycornelissen.wordpress.com/2011/05/12/push-notifications-in-ios-with-monotouch/

Whats the problem?
You have two scenarions:
Push-notification received when app is not launching. If use tap on notification, app will get data in FinishedLaunching handler;
Push-notification received when app is launching. App will get data in ReceivedRemoteNotification handler.
Article in your question shows that processNotification is the same in both scenarios. It shows how to read alert (text)/badge (count)/sound fields and your own custom payload.

Related

Why doesn't the Azure Bot Service Slack connector forward Events and Interactive Messages?

Update: June 30, 2020
After more testing, I have details that might help someone recognize my problem.
The issue seems to be that Slack is sending data to Azure Bot Services, but that data isn't being forwarded to my code. Ive been able to use the Bot Emulator without any problems and the Azure Web Chat works fine.
I know that the Slack configuration for the OAuth Redirect URL is correct (I was able to add my bot to Slack) and the Request URL for Events is correct (they sent the 'challenge' and it's verified). I've subscribed to the exact Scopes and Events that are in the Microsoft documentation and I've verified that the Interactivity and Events options are enabled.
When a user types text in my bot's Slack channel, my app receives "message" activity and my code can send a response, so it looks like Microsoft can communicate end-to-end for normal messages. I do not receive any data when users first join my bot (like a ConversationUpdate) or if they click a button in a dialog. I can see Slack sending data when a button is pressed, it just never arrives.
As a test, I copied the Messaging Endpoint from my Azure bot settings and pasted it into Slack's Interactivity "Request URL" and when I click a button in Slack I can see the data that Slack is sending (sadly in a format that my code can't handle).
Original Post
I have a Bot Framework app (v4) that I've written in nodejs. It works well and I have an ActivityHandler that responds to people being added to a conversation and when they send messages. I was able to get pro-active messaging functioning and everything was great until I tried to get interactivity working.
I started off using some sample button code from Microsoft's documentation:
let reply = MessageFactory.suggestedActions(['Red', 'Yellow', 'Blue'], 'What is the best color?');
await turnContext.sendActivity(reply);
This works fine in the emulator, but in Slack it renders as a bulleted list. It looks like that's the way that "suggested actions" are handled in Slack.
I changed my code to use a "hero card":
let card = CardFactory.heroCard(
'What is the best color?',
undefined,
CardFactory.actions([
{
type: 'imBack',
title: 'Color Red',
value: 'Red Value'
}
])
);
let reply = MessageFactory.attachment(card);
await turnContext.sendActivity(reply);
This works okay in the emulator, except my app thinks the user typed "Red Value" and the button stays on-screen and is still clickable. I might be able to work around that, but the button doesn't work at all in Slack. It is rendered fine, but I don't get a notification in my app.
Clicking the button shows an HTTP request to:
https://{MY_SLACK}.slack.com/api/chat.attachmentAction?_x_id=f8d003c3-1592436018.632&_x_csid=NcWi3y50lFU&slack_route={OTHER_SLACK_STUFF}
And I can see that the request POSTs all sorts of data including:
payload: {"actions":[{"id":"1","name":"imBack","text":"Color Red","type":"button","value":"Red Value","style":"default"}],"attachment_id":"2","callback_id":"{MAGIC_NUMBER}:{TEAM_ID}","channel_id":"{CHANNEL_ID}","message_ts":"1592435983.056000","prompt_app_install":false,"team_id":"{TEAM_ID}"}
I'm not sure how to see anything useful in the Azure Portal - the analytics option for my bot doesn't seem to work and the activities option only says "Write a Bot Service". I don't see any sign of the message going from Slack to Azure.
I'm developing locally and configured ngrok so that my messaging endpoint in Azure could be set to https://69fe1382ce17.ngrok.io/api/messages On the Slack side of things, I've configured the Interactivity Request URL to be https://slack.botframework.com/api/Actions The Event Subscription Request URL is https://slack.botframework.com/api/Events/{MY_BOT_NAME}
What I would like is a set of buttons with different options and when the user clicks one, my bot gets some sort of "value" instead of message text. I'd also like for the button to go away so the user can't send repeated commands. It would be nice if the hero card collapsed with just the prompt being displayed.
Are there any interactive options that work for Slack and other channels?
Thanks!
Lee
I know linking to another site with no additional detail is frowned upon, but I don't have enough expertise to answer your question. I suspect the link here might move you in the right direction:
Choice Prompts are not translated over to Slack format #3974
Good luck!
Your question is multifaceted so I'll try to break it down into smaller pieces.
What's the deal with suggested actions in Slack?
Suggested actions are not supported in Slack, but the Bot Builder SDK thinks they are. This is a longstanding bug. I've just reported it again on the docs page you linked: https://github.com/MicrosoftDocs/bot-docs/issues/1742
This means you would encounter problems if you were trying to have the choice factory automatically generate the right kind of choices for your channel. You're not doing that, so you should be fine. Hero cards are supposed to work in Slack.
Why aren't hero cards working in Slack?
First I need to mention that hero cards only work with the Slack connector and not the Slack adapter. You seem to be using the connector so you should be fine.
I suspect your problem is related to how you've configured your bot's settings on the Slack side. There is a step in the Bot Framework doc that seems to be important if you want to get buttons to work. If you've followed the doc exactly and you still can't get buttons to work, it may be worthwhile to dig into the Slack API documentation.
How do I only allow a button to be clicked once?
You can update or delete the activity. There's no easy way to do this, but if you voice your support for my cards library then it can be done for you automatically.
The Slack connector actually puts a lot of relevant information in the incoming activity's channel data, and you can use that to figure out what activity the incoming activity came from. That would take some experimentation on your part.
There's another approach that works on more channels than just Slack. It's real complicated, but if you wanna tackle this then here are the basic steps:
You need to put an ID in the action data to help your bot identify the action.
You need to save the activity ID that gets returned when you send the action to Slack.
You need to associate the returned activity ID with the ID you put in the action data.
You need to retrieve the activity ID using the action data ID when the user clicks the button.
You need to use that activity ID to update or delete the activity.
Unfortunately there's no centralized guide to help you do this, but there are many examples explaining it scattered across Stack Overflow. Here is a good one: https://stackoverflow.com/a/55174866/2122672

Is there any way to use a received sms as a trigger in a logic app if it's not the initial trigger?

I'm trying to use a twilio sms as a trigger for a step in my logic app that isn't at the very start. The app is meant to simulate a conversation between the user and the app so i need the app to wait for the user to respond.
For example, a conversation might go like
User: Hi
App: Please give me an animal
User: Cat
App: Ok, you said cat
All the tutorials I've found on making a sms a trigger for a logic app just show how to use the "when an https request is received" as the very first step of the logic app. I tried adding another "when an https request is received" as an activity after the "send sms" activity where "please give me an animal" is sent but it says "you cannot use this trigger as an action."
Essentially I'm looking for an activity to make the app wait for the user to respond to "please give me an animal" before the app goes into the "ok you said..." part.
This is my first time using logic apps so I'm hoping that makes sense, please let me know if more info is needed.
Sorry you can't. There can be only one trigger. Some actions like something similar to approval flow which could be used but there isn't one for twilio.
Also what you want is really just a chatbot. I think you should look at Azure Bot Service instead. It allows for conversations thought twilio SMS as one of the channels.
https://learn.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-twilio?view=azure-bot-service-4.0
You can achieve what you are trying to do with Twilio. Twilio Studio send and wait for reply widget will wait for a reply before moving to the next widget. The example below is outbound but can easily trigger off an incoming message, by attaching the Studio Flow to that Twilio number.
Conduct a Survey with Twilio Studio
Also, Twilio Autopilot could achieve a more flexible response model.
Getting Started with Twilio Autopilot

Firebase (Google) Cloud Messaging (FCM, old GCM) - check message status

I'm trying to find a solution to ensure a push notification to my Chrome extension has been received before sending another one. IF it hasn't been received and another one should go, I would change its content to tell the user he has multiple new informations to check.
So I'm looking for a way to check the previous message status using its ID, or check the queue of messages if using a collapse key, before sending a new one. But I can't find anything related to this, except here : https://support.google.com/googleplay/android-developer/answer/2663268?hl=en there is FCM message status detailed, but no way to get them after the first response.
I am aware receipts can be implemented using XMPP but I would really prefer to remain on the regular HTTP protocol.
Thanks ahead for any help.
XMPP receipts would be the recommended way for you to get an ack that the message was delivered. You can also use the Play Developer console (Android developer console) to view statistics on the status of messages. However this will not be sufficient if you want to automatically resend, you would have to do this manually.

Registering Two templates with Notification hub and send Notifications

Motive :- I want to send the both Toast and Tile Notification Simultaneously to my Windows Phone 8.1 App.
=> I am using Templates Feature with Notifications Hub to send the localized notifications.
Everything is working fine When I register only Toast/Tile Templates(One at a time) with Notificationhub Client.
await _hubClient.CreateWindowsTemplateRegistrationAsync(model.ChannelUri, toasttemplate, tags);
Problem :- But when i register the Both Toast and Tile Templates With hub then in that case it is not able send Both notifications. There is no error indication..
So anybody know how can register and send both notifications simultaneously ?
Any pointer or help is really appreciated.
I have posted my answer on microsoft forms Get a hint from there, It is working fine, Reference :- Microsoft Notification Forum
It is little bit less understandable but i am adding some stuff in support of forum answer.
Template registrations will be differentiated with reference to
set of tags they are registered with. For example, suppose you are
registering a set of same tags with both the Tile and Toast
Notifications template registration, in that case Notification hub
would not be able to differentiate which type of notification you are
sending.
Solution :- when you are registering with notification hub just add a extra new tag i.e. for toast = "toast" and for tile = "tile", for differentiating two different registrations. And when you are sending the notification to devices, you have to use Tags Expression for targeting the Toast and Tile differently.
For Example :- For sending toast notification to tag1 you have to use "tag1&&toast" expression. For Tile you have to use "tag1&&tile".
I have spent a lot of time to made the both notifications work simultaneously, Just go through with this answer and Forum answer. You will get your solution.
Hope it'll help somebody.

Call server in background

I'm building an iPhone-app in which the logged in users can chat to each other. It's very like the Wordfeud chat for example. You click a user and a modal view controller shows up where you chat.
I have set up a push notification server that works, I just need to know just how I should use it.
When the chat view controller is open I poll in the background with ASIHttpRequest every tenth second to see if a message has been sent from the user you chat with. This works perfectly fine.
But what happends when i close the chat view controller to do something else in the app. Should I create a ASIHttpRequest in every single view controller in the app to poll for new messages or is it here the push notification service takes over? Even though the app is still open?
Or shouldn't I send push notifications when the app is running, only when it's not running?
If that's the case I guess I have to send a request to the server which says that the app is has now been closed (here is a problem if the app crashed out of the blue).
I would be really greatful for some guidelines here, I have searched the web but there are old discussions which confuses me, and some new ones where many people says different.

Resources