rocket.chat uploading to inaccessible room - node.js

I am writing a slashcommand with the Rocket.Chat.Apps-engine for my Rocket.Chat Server which exports the chat in the current room, creates a pdf and uploads this back into the room. I am using an own node server for the generation and upload. However, my bot-user does not have access to lets say direct chats, private rooms also not. One could invite the bot into every new private room, but the direct chat problem stays. Is there a ways to somehow use the Rest Api to write a message to such rooms? I am using access tokens for authorization.
So far I can read all the chats with the /api/v1/im.messages.others endpoint (also those my bot cannot access), now I need to have some endpoint or similar to write something to the rooms which my bot cannot see.

Related

Send notification to one user with firebase cloud function node

I am trying to send a notification to a specific user using FCM, but I haven't found a way. I have a mobile app and a node server running.
I want to be able to send a notification when the shipment status changes. I have already a function for it in my server I just have to send the notification to the user. Is it possible to achieve this using nodejs or is there a way to implement it in flutter?
I found this code
    var FCM = require('fcm-node')
var serverKey = require('path/to/privatekey.json') //put the generated private key path here            
var fcm = new FCM(serverKey)     
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)        
to: 'registration_token',         
collapse_key: 'your_collapse_key',                
notification: {            
title: 'Title of your push notification',             
body: 'Body of your push notification'         
},                
data: {  //you can send only notification or only data(or include both)            
my_key: 'my value',            
my_another_key: 'my another value'        
}    
}        
fcm.send(message, function(err, response){        
if (err) {            
console.log("Something has gone wrong!")        
} else {            
console.log("Successfully sent with response: ", response)        
this is a npm package taht lets send a notification but it asks for a registration token.
I hope you can help me. Thanks in advance!
Firebase Cloud Messaging has no concept of a user. Instead it can send messages to:
Specific app instances (so your specific app as installed on one specific device), as identified by an FCM/device token.
A group of app instances/tokens, as defined by your application logic.
A specific topic, to which app instances can then subscribe.
It's up to your application logic to decide how to map from your user ID to one of these options. The most common are to:
Store the device token(s) and your user ID in your own database, then look up the device token(s) for a user when needed and fill them in to the API call you already have.
Use a specific topic for each user ID, subscribe the application to that when it starts, and then send a message to that topic when needed. Note that anyone can subscribe to any topic though, so this approach would allow folks to receive message for anyone whose user ID they know.

Secure messaging system with chat history

I would like to create a messaging app that will be available both on website and mobile ie users can access there messages with their account both on the website and the app.
Now, the issue is that in order to keep the history of the messages I must save them somehow in the database. I do not want to save them in plain text to avoid any data stealing (the app might go in production someday). But, I do not see any way to save the messages encrypted in the database and decrypt them for both the sender and receiver.
What I thought about doing is to create two instances of each message sent in the db. One being encrypted with the sender's public key and the other one being encrypted with the receiver's public key. This way both sender and receiver will be able to decrypt every single message saved in the discussion with their private key.
However, I do not if this is the best way of doing it, what do you think about? Also, I guess the private key will be stored on the user's device but what would happen if the user deletes the app or changes device. Furthemore what about the website? How will it access the private key if it is on the user's mobile device?
Fyi I am using NodeJS, MongoDB, React, React Native and Socket.io

Sending Firebase Notification with nodejs

I have an android app on which I want to send notification via my web app.
How do I send Firebase Cloud Messaging notification with nodejs? I have found a lot of examples and posts on this subject, but in all of them you are supposed to just paste device Token and send notification to that device. If I wanted to use it that way, I would be able to simply implement this from official documentation.
The thing is, I need to receive user id from database so I know which user I want to send notification. After I have user id I can then retrieve device Token from the same database. I get both user id and device token on client side. And documentation refers to server side.
This all happen after button click. So, I don't understand how to send notification on server side, meaning, I don't have there all those informations I need - user id, device token and message info that contain some other database info. Do I pass those arguments from client side to server side somehow, or is there a way of using modules like "require()" on client side?
What is the best approach here?
You will need to implement a device token registry to fit with your use case. So if you want to send messages to users, then you will need a registry (really just a fancy word for a database) of the token(s) for each user. Then when you want to send a specific user a message, you look up their token(s) in the registry, and call the FCM API to send messages to them. Since you mention Node.js, you can likely do this using the Firebase Admin SDK: https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices.
An alternative I have once written article about using a topic for each user, which saves having to have a registry of their tokens. While this is less secure (since anyone who knows a topic, can subscribe to it), it is definitely easier to implement.

How to Auth from an external service to the bot framework?

I have an external service with is own database where the users can log in.
Now I have a bot in NodeJS using Bot Builder and the Bot Framework.
I want to link them.
Is there anyway that the bot recognize the users from the other service everytime they open a new conversation and everytime they write something in the bot?
I've just tried with web chat before and I know that with channels that they support like Facebook, Telegram, Skype etc is easy to recognize the users every time they come back, but I don't know how if it is possible to do this with an external service where the users are already logged in and they want to talk with the chatbot.
I don't know how could I generate an authtoken or something that the bot framework read it and recognize the user.
You can use the DirectLine API to allow your bot and a custom client to communicate to each other, a sample can be found here, and here if you want to use WebSockets.
You can also add authentication to your bot via Azure Bot Service to use OAuth as stated here, where you will find samples too.

Communicating with the web server using Google Home

I have a social networking website developed in php which is hosted on the server. Here people can talk to each other through messages.
I want to send and receive the messages, to the other users through google home. It is not like a chat bot. But here, the first user will send message from google home to the website and then the second user will send the message from the website to the first user who will receive it through google home.
Can this be achieved? Do I have to develop some kind of mobile App, so that user has to send the message to the mobile app and then the app sends the data to the server.
or do i have to use the webhook which is available in api.ai?
Any help will be appreciated.
You do not need a mobile app - it sounds like most (but not all) of what you're trying to do would be handled using API.AI's webhook Fulfillment.
However, you're also trying to do asynchronous operations (send a message or a notification to Home without the user prompting for it). This currently isn't possible - you can currently only send a message in response to the user taking some action.
One possible workaround for you is to allow the user to ask "how many messages are waiting for me" or something similar at any point. You can also play multiple messages in reply to a message they might send. However, you have limits (about 5 seconds) on how long you can wait to send a reply to a user instruction.
You can implement a chat bot e.g. via Dialogflow (former api.ai), however you can just react on inputs. You cannot push a message on Google Home (yet). So you could the bot read your mailbox but not implement a chat.

Resources