PowerAppsNotification.SendPushNotification New Data data - push-notification

In powerapps I want to send notification to users with newly created record details. I'm using following code to push notification(onsuccess).
in edit mode, the code is working fine (sending notification with details) but in case of newform(createform), the notifications are being send of the 1st record of the table in which data is being inserted.
any idea whats wrong ?
PowerAppsNotification.SendPushNotification(
{
recipients: [
"User1 mail ID",
"User2 mail ID",
"User3 mail ID"
],
message: "New Repair request Created ("& DataCardValue12_1.Text &": "& DataCardValue21_1.Text& )",
openApp: true
}
)

Related

Telegram bot sends "my_chat_member" object instead of "message" object on start via webhook

I have a telegram bot where the user can send /start command and I will receive this command on my server via web hook. In 99% of cases the request from telegram looks like this:
{
"update_id":99999999,
"message":{
"message_id":9999,
"from":{
"id":999999999,
"is_bot":false,
"first_name":"first_name",
"last_name":"last_name",
"language_code":"code"
},
"chat":{
"id":99999999,
"first_name":"first_name",
"last_name":"last_name",
"type":"private"
},
"date":1665383118,
"text":"/start",
"entities":[
{
"offset":0,
"length":6,
"type":"bot_command"
}
]
}
}
The object is "message" and I have a text "/start" there.
But sometimes from some new users who hasn't used this bot before when they send start the request from telegram look like this:
{
"update_id":999999999,
"my_chat_member":{
"chat":{
"id":999999999,
"first_name":"first_name",
"type":"private"
},
"from":{
"id":999999999,
"is_bot":false,
"first_name":"first_name",
"language_code":"code"
},
"date":1665381194,
"old_chat_member":{
"user":{
"id":8888888888,
"is_bot":true,
"first_name":"bot_name",
"username":"bot_name"
},
"status":"member"
},
"new_chat_member":{
"user":{
"id":8888888888,
"is_bot":true,
"first_name":"bot_name",
"username":"bot_name"
},
"status":"kicked",
"until_date":0
}
}
}
The object "my_chat_member" and the "start" command was not received from this user.
This happens for users on IPhone, Android, PC, Web.
I can't understand why it happens and how to fix.
The problem was on my server side. I used int32 for users' and chats' ids but they can be bigger. Using the correct type solved the problem.
Message type "my_chat_member" means somebody described as "from" wants to unsubscribe from bot. "status":"kicked" says the same. Here https://core.telegram.org/bots/api you can read Getting updates topic

Get Reply Message from Telegram Bot API

I'm developing a Bot that I want users to call in a reply to a previous message. So you would reply to a message with the bot command.
For Example
User 1: Hello World
User 2: (Reply to Hello World) /command test message
Right now I am only able to grab the text sent directly in the command ("test message"), but not the first message ("Hello World"). According to their documentation, I should be able to get it from reply_to_message. However, all I'm seeing in my logs from the webhook is this.
event: {
body: {
update_id: 5632431,
message: {
message_id: 43,
from: {
id: < my_user_id > ,
first_name: 'User 2',
username: 'user_2_username',
language_code: 'en'
},
chat: {
id: < chat_id > ,
title: < chat_name > ,
type: 'group',
all_members_are_administrators: true
},
date: 1498342725,
text: '/command test message',
entities: [{
type: 'bot_command',
offset: 0,
length: 5
}]
}
}
}
Am I doing something wrong? Anyone have experience getting a reply message?
Any help would be appreciated.
Goto #BotFather, and turn off privacy mode
/setprivacy — Set which messages your bot will receive when added to a group. With privacy mode disabled, the bot will receive all messages.
You might need re-add your bot to group after set this.
When a bot is in privacy mode then it will only receive (copied from docs):
Messages that start with a slash ‘/’ (see Commands above)
Replies to the bot's own messages
Service messages (people added or removed from the group, etc.)
Messages from channels where it's a member
This does not include messages that were replied to.
Privacy mode is enabled by default for all bots, except bots that were added to the group as admins (bot admins always receive all messages).
So the only way to get messages being replied to is to disable privacy mode as Sean suggested.
I was dealing with the same problem recently, two things worked for me:
1 - Disable Privacy Mode and,
2 - Using #botname for mentions (no /botname), that way I was able to get reply_to_message field.
Sharing my code; try this, it should succeed.
$chatID = $this->getChatID();
$sendto = API_URL . "sendmessage?chat_id=" . $chatID . "&text=" . urlencode($msg) . "&reply_to_message_id=" . $messageID;
file_get_contents($sendto);

Messenger bot with checkbox plugin how to keep track of the conversation with user ref and user id

We'd like to add the facebook messenger checkbox plugin at the end of a request form so users can opt-in for notifications via messenger.
When the user opts in, our webhook receives a callback with the user_ref that we set in the form.
We send a confirmation of opt-in to this user_ref
But other messages we receive like delivery, read receipt or actual messages from the user do contain the user ref anymore but the user id.
This is the official documentation of facebook:
After you receive the callback event, you can call the Send API to start messaging the user using the user_ref identifier in recipient as shown below. Note that this field is the same as the unique user_ref param used before when the plugin was rendered and in confirming the opt-in.
If the call to the Send API is successful, the response will contain a recipient_id parameter, which is a stable user ID that you can now use in future API calls.
Therefore it's impossible to keep track between the initial message and new ones. Does anyone found a solution for this?
Thank you very much in advance.
You can, for example, send additional information when the user opts in using the optional ref parameter. You can send the username of the user logged on my website:
function confirmOptIn() {
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
'app_id':'APP_ID',
'page_id':'PAGE_ID',
'ref': 'myuser#mywebsite.com',
'user_ref':'UNIQUE_REF_PARAM'
});
You will receive the username within optin in your webhook event:
{
"recipient":{
"id":"PAGE_ID"
},
"timestamp":1234567890,
"optin":{
"ref":"myuser#mywebsite.com",
"user_ref":"UNIQUE_REF_PARAM"
}
}
Then, you can call the Send API to start messaging the user using the user_ref.
If the call to the Send API is successful, the response will contain a recipient_id parameter, which is a stable user ID that you can now use in future API calls.
...so you will received the Messenger ID which you can map to the username of your website you already have. Here, I modified a little the example from the official developers site to call the send API with user_ref and map the user ID I get in the response to the username of my website:
function callSendAPICheckbox(messageData, userApplicationId) {
((userApplicationId) => {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: {
access_token: PAGE_ACCESS_TOKEN
},
method: 'POST',
json: messageData
},
function(error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
if (messageId) {
console.log("Map messenger user ID %s with the username of my website %s", recipientId, userApplicationId);
} else {
console.log("Successfully called Send API for recipient %s",
recipientId);
}
} else {
console.error("Failed calling Send API for userId " +
recipientId, response.statusCode, response.statusMessage, body.error);
}
});
})(userApplicationId)
}
Why don't you make use of metadata field of sendTextMessage. Each and every message you send to your user, you send the metadata too, and when you receive response of the message being delivered, you find the metadata field in it.
Here is what I do:
When user select the checkbox plugin and event is triggered I receive the call on my server, check if it contains user_ref. If it does, then I send a text message to user with a custom metadata using user_ref. When user receives the message, the webhook send me a json data as mentioned in the documentation. To identify for which user_ref I have received this response, I set custom metadata which is combination of some string + user_ref before sending the message to user using user_ref. Using this custom metadata I identify the sender.id of the user for which I previously sent message using user_ref. The sender.id is my pageid and recipient.id the the user id which you are trying to get and using which we generally send message to the user and is also know as psid.
Above if just the logical part mentioned which I usually do.
For detail solution along with code, I have already posted it here:

IBM Mobilefirst: Is there a way I can send a push notification to deviceid irrespective of user

I want to subscribe multiple users to a device for push notification in MFP. which i assume is not possible.
So what I want to do is i want to send my notification on the basis of deviceid ignoring user. Is this possible.
I see two methods which send notification to a device, but they still need userid is what i see.
WL.Server.notifyDevice(userSubscription, deviceId, notification);
WL.Server.notifyDeviceSubscription(deviceSubscription, notificationOptions)
Is there any other way, Please suggest.
Yes, You can send push notification targeted to deviceId using multiple ways.
You can use sendMessage API where you can specify deviceIds in Target Parameter. In this case only those deviceIds will receive the notification.
More Details about API : https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html#sendMessage
Send Message REST API where you need to add target as deviceIds.
The following is the payload example.
{
"message" : {
"alert" : "Test message",
},
"target" : {
"deviceIds" : [ "MyDeviceId1", ... ]
},
}
More details about API : https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/rest_runtime/r_restapi_send_message_post.html

Linking Robomongo to an automatic email sending service?

I have an application running on meteor.js and mongo.db. I am using robomongo as a tool for mongo.db. Now I'd like to do the following:
1. Somebody registers with my service (adding email to db)
2. I want to send an automatic welcome email to that person.
Is there any possibility how to do it?
You need an email server (SMTP), and then use the meteor email library. If you don't have an email server and don't want to create one, use a commercial solution. (Example)
Full working example you can find here: http://meteorpad.com/pad/iNMBHtNsv7XKHeq44
Notice it creates new users from within Meteor app, but the same effect will be when you use Robomongo or any other way of updating MongoDB.
First install package Email to be able to use Email.send.
In below example I assume that adding new user to collection Meteor.users should fire sending "invitation" email.
In very similar way you can detect if email was added to user object
(user.emails.length was changed) and then send email.
Then take a look at code:
// SERVER SIDE CODE:
Meteor.startup(function () {
// clean users on app resetart
// Meteor.users.remove({});
if(Meteor.users.find().count() === 0){
console.log("Create users");
Accounts.createUser({
username:"userA",
email:"userA#example.com",
profile:{
invitationEmailSend:false
}
}) ;
Accounts.createUser({
username:"userB",
email:"userB#example.com",
profile:{
invitationEmailSend:false
}
})
}
Meteor.users.find().observe({
added:function(user){
console.log(user.username, user.profile.invitationEmailSend)
if(!user.profile.invitationEmailSend){
Email.send({
from: "from#mailinator.com",
to: user.emails[0].address,
subject: "Welcome",
text: "Welcome !"
});
// set flag 'invitationEmailSend' to true, so email won't be send twice in the future ( ex. during restart of app)
Meteor.users.update({_id:user._id},{$set:{"profile.invitationEmailSend":true}});
}
}
})
});
Above code will send email to users who don't have flag equal to true in profile.invitationEmailSend. After e-mail is sent server updates user document in db and set user.profile.invitationEmailSend to true.
Whenever you add users to mongoDB (using Robomongo or any other way), then added function is executed and e-mail is send only to new users.

Resources