How do we mention the conversation id in the botframework webchat instead of it being randomly generated? We can currently mention the userid and username for the webchat but could not have the conversation id mentioned.
For more information on this subject, check out the guide: Send proactive messages.
To be able to send an ad hoc message to a user, the bot must first collect and save information about the user from the current conversation. The address property of the message includes all of the information that the bot will need to send an ad hoc message to the user later.
bot.dialog('/', function(session, args) {
var savedAddress = session.message.address;
// (Save this information somewhere that it can be accessed later, such as in a database.)
var message = 'Hello user, good to meet you! I now know your address and can send you notifications in the future.';
session.send(message);
});
After the bot has collected information about the user, it can send an ad hoc proactive message to the user at any time. To do so, it simply retrieves the user data that it stored previously, constructs the message, and sends it.
function sendProactiveMessage(address) {
var msg = new builder.Message().address(address);
msg.text('Hello, this is a notification');
msg.textLocale('en-US');
bot.send(msg);
}
Related
guys! I have a task to create AWS lambda endpoint for resetting user's password. I have to send a new password to user's email. I have read a lot about SNS and SES and currently have no idea what service is better for my purpose. Will be glad to hear from you advice!
Here is my lambda code
const requestData = AdminResetPasswordDto.from(event.body);
const errors = await AdminResetPasswordDto.validate(requestData);
if (errors) {
return new BadRequestError({ message: "errors.invalid-request-params", errors })
}
const repo = new UsersRepo();
const entity = await repo.getOneByEmail(requestData.email);
if (!entity) {
return new BadRequestError({ message: 'errors.user-not-exists' })
}
// const newPass = generatePassword();
// sending newPass to user via SNS
// use SNS or SES ???
// https://docs.aws.amazon.com/sns/latest/dg/sns-email-notifications.html
const user = UserDto.fromEntity(entity);
const result = await repo.updateUserPassword(user.userId, user.userRole, newPass);
if (!result) {
return new BadRequestError({ message: 'errors.password-not-updated' })
}
return new ResponseSuccessNoBody();
SES is meant for sending high-volume e-mail efficiently and securely. Once you have verified that you are the owner of an e-mail address, you can send e-mails through SES to any other e-mail address without the recipient's consent. SES takes care of the engineering required to ensure the delivery of their e-mails.
SNS is meant as a channel publisher/subscriber service. In order to receive e-mails from SNS, the end-user must first subscribe and approve that subscription through e-mail before amazon delivers e-mails from the subscribed channel to that end-user. End-users can subscribe via e-mail, SMS, webhooks, and other means up to the user independent of the publisher.
On a practical level, we use SES to send our users e-mails about their content and we use SNS to send our developers notifications (via SMS and e-mail) when servers go down or have issues.
In short,
SNS
email messages
SMS
push notifications to mobile device
messages between services/apps
Clients have to subscribe, to receive above notifications
SES
email messages
No subscriptions required
SNS is used for “technical” notifications; delivery as e-mail is possible, but rather limited. First, you need to create dedicated subscriptions and provide the destination mail address at this point. Second, you can’t really “design” your messages, it will just be a blob of text. You should go with SES for messages where the recipient is determined at runtime and you want to have control over the message layout.
I am trying to send personal message to particular user using webhook. I created webhook so i am getting personal message. But I am not able to send personal message to others personal chat. I don't want to use bot.
slack.setWebhook("Webhook");
slack.webhook({
channel: "D01KMUZ4E4S",
username: "webhookbot",
text: "This is posted to #general and comes from a bot named webhookbot."
}, function(err, response) {
console.log(response);
});
Slack Webhook URLs are tied to a particular channel, individual message, or group message. You need to create a new webhook in your workspace for each user you would like to send messages to.
Background
I posted a question a few days ago and gained some insight: previous question. However, I did a poor job asking the question so I still don't know how I can retrieve all the users FCM tokens in order to use something like this: Subscribe the client app to a topic. This is also listed under the Server Environments documentation. My clients are on the iOS platform.
This function requires the client FCM tokens to be in a list to iterate over and subscribe each client to a topic to later be used for push notifications. Also I have almost 3,000 users which is more than the 1,000 device limit noted in the documentation.
I was also directed to some server documentation by another clever answer: Manage relationship maps for multiple app instances. However, after reading through the material I still believe I need an array of client registration tokens to use this method. My analysis could be totally incorrect. I am quite ignorant since I'm very young and have a ton to learn.
I also tried to get the client FCM tokens with Bulk retrieve user data, but this does not have access to device tokens.
Question
How cant I obtain all of the users registration tokens to provide to this function:
var registrationTokens = [];
admin.messaging().subscribeToTopic(registrationTokens, topic)
.then(function(response) {
console.log('Successfully subscribed to topic:', response);
})
.catch(function(error) {
console.log('Error subscribing to topic:', error);
});
Furthermore, if I have over 1000 users, let's say 3000. How can I make separate request to subscribe everyone and not surpass the 1000 device per request limit?
Additional question on device groups
I've been trying to accomplish a "Global" push notification by sending messages with topics. Is sending messages to device groups perhaps a better approach?
send different messages to different phone models, your servers can add/remove registrations to the appropriate groups and send the appropriate message to each group
After reading the documentation they both seem adequately to accomplish my goal, however, device groups allows the server to more accurately send messages to specified devices. Are one of these methods a better practice? Or for my case is the difference trivial?
The thing about tokens here is that they can change at any time like:
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.
so even if you save them some where then try to register them all at once, some of them may not be valid at that time.
better way to do this is form your registaration token on your client side (IOS):
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
print("FCM registration token: \(token)")
self.fcmRegTokenMessage.text = "Remote FCM registration token: \(token)"
}
}
then monitor changes on this token:
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
and send changes to server (which can be any type of servers here) like Firebase Functions with Nodejs. Check here to know how to post a request to Firebase HTTP functions. Then, you can use the same code that you have posted here within that function to register the token to the topic.
This way, you will never exceed that limit and you keep track of all the users' registeration tokens changes.
Hi, We have created a bot where user interact with the bot. so our
bot has two type of queries static and dynamic queries. if user asks
static query we don't ask for SIGN IN but if user ask for dynamic
query than we ask user to SIGN IN and redirect to SIGN IN page than
we ask mobile no and dob and send OTP to user and than verify the
user and send back a token in response which we get in further
request. The problem is let use suppose user came on our our bot and
asked static query so i store the chat of user to my db initially I
create a userId for user like this conv.user.storage.userId =
'unique_id' and store this unique_id in my db to identify the user
next time and send back. Next time same bot get same userId and keep
updating my chat in db for this userId. Now the problem comes when
users asks a dynamic query than I have to redirect user to our
account linking page. user is redirectd to account linking page and
user fill his mobile no. and DOb and we send a otp to usermobile.
When our SendOtp api is called I create a userId and store in
databse but I want the userId which I set before for static queries
(conv.user.storeage.userId) this one. How can I get this Id. Can we
pass this userId as params to when to ask for SIGN In (conv.ask(new
SignIn('To get your account details'))) and get this static query
userId in my SendOtp API. I need same ID to send further to update
chat.
When you create a SignIn request, you cannot provide any additional data in that request. However, you are able to provide this behavior when your Action gets a callback. You will get a Sign In event that can be set to when the user signs in. At that point you can add your additional logic to connect the user's account on your backend with the account ID in userStorage.
Here's an example of what it may look like.
app.handle('linkAccount', async conv => {
let payload = conv.headers.authorization;
if (payload) {
// Perform account merge
await performAccountMerge(payload.email, conv.user.storage.userId)
}
});
async function performAccountMerge(authorizedEmail, savedUserId) {
await saveInDatabaseForEmail(authorizedEmail, savedUserId)
}
Clarifying my post:
I'm setting up a facebook chatbot using the sample code. This should allow me to send messages to the chatbot (via Messenger iOS app, or via chat window at Facebook.com, app page). The expected behavior would be
Send chat message
Echo chat message
Display correct logging, no errors
However, when I send a chat message, while it correctly echoes the chat message, I am finding an error in my logging. It produces the following error message:
{ message: '(#100) No matching user found',
type: 'OAuthException',
code: 100,
fbtrace_id: 'D+PAc3ZfmLS' }
After investigation, it appears as though the app is identifying the incorrect userID for my account (app owner). It has the correct receiver ID (page ID of the application). I cannot figure out why this occurs. A copy of typical logging information is below. The incorrect sender ID is listed as "1053426944750274".
Received message for user 1053426944750274 and page 289085874757891 at 2016-07-06T20:32:31+00:00 with message: {"mid":"mid.1467837151667:954f158fd950334f60", "seq":212, "text":"marco"}
Successfully sent generic message with id mid.1467837152021:729cf052bc826dc592 to recipient 1053426944750274
Received message for user 289085874757891 and page 1053426944750274 at 2016-07-06T20:32:32+00:00 with message: {"is_echo":true,"app_id":284007785268790, "mid":"mid.1467837152021:729cf052bc826dc592", "seq":213, "text":"marco"}
Are you sure you are using the sender.id in the message recipient.id?
be aware that Facebook id is different than what you need to use when you respond to users via messenger send API.
When representing a user, these IDs are page-scoped IDs (PSID). This means that the IDs of users are unique for a given page.
If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.
source