Identify first sign in with Authentication using AD for Microsoft Bot Framework - botframework

I would like to give a login successful message to the user when he sign in for the first time. So i need to identify weather the user have used sign card shown to sign in(user have interacted) or system automatically taken the token itself without user intervention. It will be nice we show a successful message user interaction was there. How i can identify weather there was a user interaction or not?

The answer I found is to find the Activity Type if its event type user have interacted else it’s an automatic signin. You can reverify the connection just established by checking the value of key connectionName in Activity.Value. The following code will help you.
string output = JsonConvert.SerializeObject(stepContext.Context.Activity.Value, Formatting.Indented);
if (stepContext.Context.Activity.Type is "event")
{
var conName = JsonConvert.DeserializeObject<JObject>(output)["connectionName"].ToString();
if (conName ==<Your Connection Name>)
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"You have successfully Signed In"), cancellationToken);
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"How can I help you?"), cancellationToken);
}
}

Related

How to make a bot reaction to the end of the interaction?

I mean when it went long after the interaction has been created and the user again chooses a item from selectmenu and I want a bot to respond to the user
Code callbakck:
async def callback(iter:discord.Interaction):
if menu.values[0] == '1':
if iter.is_expired is True:
await iter.response.send_message(embed=discord.Embed(
title='Error!',
description='This interaction has expired. Please enter the appropriate command again so that it will work if necessary.',
color=0xff0000
))
else:
await iter.response.send_message(embed=discord.Embed(title='Інформація', color=settings['color'], description='You chose the category **Information**'))
That's the way I have a code not working
You can't respond to an interaction after it is expired, but you can still send a message to the channel assuming you have the proper permissions.
Also I'd highly recommend calling the Interaction variable interaction rather than iter since it is more readable.
eg.
await interaction.channel.send("interaction expired")
Also is_expired() is a method, so you may need to call it with parentheses.

How to handle new_chat_members when a user joined to telegram group with telegram bot?

I'm trying to send a message to user, who joined to a group, with my telegram bot. I add bot to the group and bot is admin in group. and I set the Group Privacy off. I get user with new_chat_member when user joined to group, but the message send to user infinitely. And the update which is for when a member join to group is pending.
if(isset($arrayMessage['message'])) {
if (isset($arrayMessage['message']['new_chat_member'])) {
$text= "hello!";
$url= "https://api.telegram.org/bot".$token."/sendMessage?chat_id=".$chat_id."&text=".$text;
file_get_contents($url);
}
}
I'll assume you are using long polling for this answer. When using the getUpdates method, it will keep retrieving the existing unconfirmed updates until you confirm them by using the offset parameter.
See enter link description here
If you do not confirm the updates, you will keep receiving the same update, thus the infinite messages.

How to store conversation had with Alexa into database

I am developing an Alexa skill for school, my client wants to store the conversation what Alexa had with parents and want to display it in the student's dashboard. How to store the whole conversation had with my skill into database?
You will not get the skill user utterance or what the user has said. But, with what you get from Alexa request, you can kind-of re-create the conversation flow.
Use these information:
userId
If you don't have account linking in your skill, you will have to persist this to filter out conversations from a particular user. Please note that this userId will change when the user disable and re-enable your skill.
sessionId
If you want to filter out a user's particular session. You can also depend on SessionEndedRequest to check know when the session ended, but this is clean.
Intents
You wont get the user speech, but from intents you can identify the users intention. This will help you to guess what the user might have said.
Slots
If you combine slots with the mapped intents you will get some more information. Since slot values are always passed to you, you can persist this and will know the exact value the user has said in his/her conversation.
Timestamp
Always save the timestamp, this will help you to know when exactly the request came in.
Alexa Response
Always persist the response you send back.
sessionAttributes
If you have some cruicial information which you think will be helpful, then save it too.
With these information/filters if you sort it with timestamp, you will get an idea about a particular/all user's conversation with Alexa.
You can get and store/save what alexa says but you can not get exactly what the user say to alexa skill. But what you can get is user's intention (i.e what intent is called).
Solution to your problem is to use some database and make a table and do something like this in every intent
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'You can say hello to me!';
*//write code to add speechText to a table against the intent name/sample utterence with date and time*
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
},
};

Parse Background Job can send a message to all users currently logged in?

I am new to Parse and I want to know if there is a way to schedule a Background job that starts every 3 minutes and sends a message (an integer or something) to all users that at that moment are logged in. I could not find any help here reading the guide. I hope someone can help me here.
I was in need to push information for all logged in users in several apps which were built with Parse.com.
None of the solutions introduced earlier by Emilio, because we were in need to trigger some live event for logged users only.
So we decided to work with PubNub within CloudCode in Parse : http://www.pubnub.com/blog/realtime-collaboration-sync-parse-api-pubnub/
Our strategy is to open a "channel" available for all users, and if a user is active (logged in), we are pushing to this dedicated "channel" some information which are triggered by the app, and create some new events or call to action.
This is a sample code to send information to a dedicated channel :
Parse.Cloud.define("sendPubNubMessage", function(request, response) {
var message = JSON.stringify(request.params.message);
var PubNubUrl;
var PubNubKeys;
Parse.Config.get().then(function(config) {
PubNubKeys = config.get('PubNubkeys');
}).then(function() {
PubNubUrl = 'https://pubsub.pubnub.com/publish/';
PubNubUrl+= PubNubKeys.Publish_Key + '/';
PubNubUrl+= PubNubKeys.Subscribe_Key + '/0/';
PubNubUrl+= request.params.channel +'/0/';
PubNubUrl+= message;
return Parse.Cloud.httpRequest({
url: PubNubUrl,
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}).then(function(httpResponse) {
return httpResponse;
});
}).then(function(httpResponse) {
response.success(httpResponse.text);
}, function(error) {
response.error(error);
});
});
This is an another sample code used to send a message to a dedicated channel once something was changed on a specific class :
Parse.Cloud.afterSave("your_class", function(request, response) {
if (!request.object.existed()) {
Parse.Cloud.run('sendPubNubMessage', {
'message': JSON.stringify({
'collection': 'sample',
'objectId': request.object.id
}),
'channel' : 'all' // could be request.object.get('user').id
});
}
});
#Toucouleur is right in suggesting PubNub for your Parse project. PubNub acts essentially like an open socket between client and server so that the sever can send messages to clients and vice versa. There are 70+ SDKs supported, including one here for Win Phone.
One approach for your problem would be to Subscribe all users to a Channel when they log in, and Unsubscribe from that Channel when they exit the app or timeout.
When you want to send a message you can publish to a Channel and all users Subscribed will receive that message in < 1/4 second. PubNub makes sending those messages as Push Notifications really simple as well.
Another feature you may find useful is "Presence" which can give you realtime information about who is currently Subscribed to your "Channel".
If you think a code sample would help let me know!
Here's a few ideas I came up with.
Send a push notification to all users, but don't add an alert text. No alert will show for users who have the app closed and you can handle the alert in the App Delegate. Disadvantage: Uses a lot of push notifications, and not all of them are going to be used.
When the app comes to foreground, add a flag to the PFInstallation object that specifies the user is online, when it goes to the background, set the flag to false. Send a push notification to the installations that have the flag set to true. Disadvantages: If the app crashes, you would be sending notifications to users that are not online. Updating the user twice per session can increase your Parse request count.
Add a new property to the PFInstallation object where you store the last time a user did something, you can also set it on a timer of 30s/1m while the app is open. Send a push notification to users that have been active in the last 30s/1m. Disadvantage: Updating the PFInstallation every 30 seconds might cause an increase on your Parse request count. More accuracy (smaller interval) means more requests. The longer the session length of your users, the more requests you will use.

Glympse API - PreSet a Nick Name

I want to preset the nickname of the sender which will be shown at the receiver's end while sending the Glympse Ticket.
Issue :- When first time the sender is sending a Glympse it asks for Saving and Sending with a nick name, rather I have already set a nick name with the code detailed below.
GGlympseLite glympse = GlympseLiteWrapper.instance().getGlympse();
glympse.setNickname(DCCApplication.session.getName());
While the above code works fine from the second time onwards, but it asks for the Nick Name when the user is sending the Glympse for First Time, and it asks for the nickname everytime till the User has entered once in that popup.
Please let me know why is it so?
Thanks
Your code for setting the nickname is perfect, but there is one very recent change in our SDK that is causing it to not set properly. The Glympse platform must be synchronized with the server before calling setNickname(). This change is mentioned under 2.6.54 in our change log:
https://developer.glympse.com/Content/client/full/android/guides/Glympse_Api_Android_Changelog.html
Implement GListenerLite as specified here:
Glympse API - Handle Send Ticket Operation
And listen for the LC.EVENT_SYNCED event.
#Override public void eventsOccurred(GGlympseLite glympse, int event, Object param1, Object param2)
{
if (0 != (event & LC.EVENT_SYNCED))
{
Log.d("", "Synced with server");
GlympseLiteWrapper.instance().getGlympse().setNickname(DCCApplication.session.getName());
}
}

Resources