Threaded group SMS conversations - sms

I am trying to develop a web based SMS application and one of the features I would like to have is threaded group conversations.
Imagine there are 5 people, A, B, C, D, and E. 'A' is the person using the web application and 'B','C','D','E' are on their mobile phones.
I want to create two threads such as this:
A -> (B, C, D)
A -> (B, C, E)
And track those conversations so that person A can see a threaded conversation of those separate group chats.
One way that I know that I can do this is by using multiple twilio numbers but is there a way to do it without using multiple numbers? Is there a way to embed a key or ID in the messages that are sent/received? Twilio has cookie support but that seems to be limited to two person conversations and only works for conversations that are initiated outside the app.
I looked into Plivo and Nexmo but I don't think it's possible with them either.
Is this just a limitation of SMS or is it possible to do what I am trying to do?

SMS is stateless, and there's no way to tie two messages to each other (as a thread) other than match meta data (the pairing of a to / from).
For what you're trying to do, you'll need multiple virtual numbers, as this is limitation of SMS itself.

Related

How to send an email to subscribers?

I need inputs on how I can design a simple notification system .
There is system "Z" which generates certain events (this is an external system), and there are two systems A and B (internal systems) interested in getting email notifications about those events. However, A is interested in type "error" and B is interested in type "failure" of events from Z. I am trying to design system N which will translate those events from Z and send them as an email to A and B. I am not sure how many queues/topics I require.
Please let me know if the below steps are valid/needed/or can be improved
System A and B subscribe to emails. If I use a queue or topic the response from N has to be published on that topic, but I want to send out an email.
System N is listening to queue "test" on which system Z is publishing "error" and "failure" messages.
System N read and translates the messages from "test" queue and send email to subscribers i.e. A and B
I am mainly not sure of step 1. How will A and B let system N know that they need email notifications?
It sounds to me like you should deploy some kind of MLM (i.e. mailing list manager) which both systems A and B can use to subscribe to one or more relevant lists (e.g. an "error" list and/or a "failure" list). Then system N can send emails to those lists as needed when system Z generates the corresponding events.
Here is a list of well-known MLM implementations.

How do I avoid exceeding the 5 topic limit when sending FCM notifications to certain topics while using boolean operations?

We are developing an application, the app itself is made in Ionic (Angular) and the server is running in Laravel (PHP) on an Amazon EC2 instance. The app uses the Capacitor FCM plugin to receive notifications from FCM, and the server uses Laravel FCM plugin to send notifications.
In the app, a registered user chooses several options, such as age range, address (region), gender, among other things. Let's assume we have the ages
10's~20's = age-1
30's = age-2
40's = age-3
50's = age-4
and address regions
Asia = area-1
Europe = area-2
America = area-3
Australia = area-4
and gender
Female = gender-1
Male = gender-2
The app subscribes to the topics that are based on what options the user chooses, for example, if he chooses 30's, America, and Male, then he will be subscribed to the topics age-2, area-3, and gender-2.
Here is where the problem arises.
From the server, we will need to send notifications to users that are subscribed to specific topics.
At first, we tried using boolean operations, so that when we can send notifications to people that are subscribed to the topics (age-2 or age-3) and (area-1 or area-2 or area-4) and (gender-1). The problem is, FCM does not allow more than 5 topics to be specified in the condition, in this case, 6 is being specified. (In reality, we can reach up to 17 topics in one sending)
Since that failed, we tried sending in batches, such that (age-2 or age-3) and (area-1 or area-3) will be sent in batches of
(age-2) and (area-1)
(age-2) and (area-3)
(age-3) and (area-1)
(age-3) and (area-3)
but we quickly realized that that means some people will get the notification more than once (since some fields are multiple selection, for example, a user might choose both Asia and America), and that is of course, undesirable.
We are running out of options besides using device tokens to send notifications to people individually, but we can have up to as many as 50,000 users. We are afraid that sending notifications to people individually might take some time. We are using Laravel Queue to process the sending of notifications in the background, but we are still kind of afraid of what might happen if we send notifications individually. Besides, that implementation sounds so dirty and far from optimal, which makes me think there should be better ways.
I would like to kindly ask if anyone knows of a way to solve this situation. We did consider using Amazon SNS, but it seems that SNS is lacking topic boolean conditions and it's quite difficult to implement on both app and server.
I would really, really appreciate any ideas, opinions, any guidance. I tried my best, but couldn't think of a better solution.
Thank you very much in advance!

Microsoft Graph API Mail: updating whole conversations? (mark as read or delete)

I am developing using the Microsoft Mail Graph API I'd like to provide conversation actions.
For example, if a conversation has several unread messages, marking as read the last one doesn't mark the whole conversation as read (like I'd want).
I didn't see any conversation-level API to mark as read / mark as unread or delete whole conversations.
What would be the best way to achieve conversation updates?
Thanks!
I'm afraid there are not APIs specific to email conversations. In order to process a batch of emails within a conversation, you'll need to update each message individually.
You can determine which messages belong in the conversation using the conversationId. Keep in mind however that a "conversation" is a somewhat loosely defined entity. Exchange generally gets good results but it isn't foolproof by a long shot (for example, a conversation with 10 participants, forward it to an 11th and you often end up with two threads in a single "conversation").
I would suggest using JSON batching for something like this. Batching allows you to bundle multiple Graph commands into a single call. Using batching you could update up to 20 messages at a time.

Best Performance - emit to sockets via a loop or rooms

We currently have a chat app whereby when emitting messages out to the appropriate users (could be 1 or several depending how many are in the conversation) we loop through all socket (Socket.io 2.0.2) connections to the server (NodeJS) to get a list of sockets that a user has based on a member ID value as each user could be connected from multiple devices. The code looks like this in order to determine which sockets a user has that we should be sending the message,
var sockets = Object.keys(socketList);
var results = [];
for (var key in sockets) {
if (hasOwnProperty(socketList[sockets[key]].handshake.query, 'token')) {
if (JSON.parse(socketList[sockets[key]].handshake.query.member).id === memberId) {
results.push(socketList[sockets[key]]);
}
}
}
Having to loop through the socket connections seems inefficient and I wonder is there a better way. My thought is to create a room for each user, most users will have only the one connection but some will be connected via multiple devices so they could have multiple sockets in their room. Then I would just broadcast to the appropriate rooms rather than always looping through all sockets. Given that 95% of users will only have the one socket connection I'm not sure if this approach is any more efficient or not and would appreciate some input on this.
Thanks.
First off, socket.io already creates a room for every single user. That room has the name of the socket.id. Rooms are very lightweight objects. They basically just consist of an object with all the ids of the sockets that are in the room. So, there should be no hesitancy to use rooms at all. If they fit the model of what you're doing, then use them.
As for looping yourself vs. emitting to a room, there's really no difference - use whichever makes your code simpler. When you emit to a room, all it does is loop through the sockets in the room and send to each one individually.
Having to loop through the socket connections seems inefficient and I wonder is there a better way.
The main advantage of rooms is that they are pre-built associations of sockets so you don't have to dynamically figure out which sockets you want to send to - there's already a list of sockets in the right room that you can send to. So, it would likely be a small bit more efficient to just send to all sockets in a room than to do what your code is doing because you code is dynamically trying to figure out which sockets to send to, rather than sending to an already made list. Would this make a difference? That depends upon how long the whole list of sockets is and how expensive the computation is to figure out which ones you want to send to. My guess is that it probably wouldn't make much difference either way.
Sending a message to a room is not much more efficient on the actual sending part. Each socket has to be sent the message individually so somebody (your code or the socket.io rooms code) is going to be looping through a list of sockets either way. The underlying OS does not contain a function to send a single message to multiple sockets. Each socket has to be sent to individually.
Then I would just broadcast to the appropriate rooms rather than always looping through all sockets.
Sending to a room is a programming convenience for you, but socket.io will just be looping under the covers anyway.
I would use Socket.io rooms to accomplish what you want to do.
Server side, adding a client to a chat room:
socket.join('some room');
Then I would use socket.to('some room').emit for a sender message to be sent to all participants in the room.

Stripe payment split - how to implement?

I am working on an app that will allow friends to split the cost of a service among themselves. I am wondering if
a) this is possible via Stripe
b) is there any working example of this / code that I can look at?
c) any security issues that arise specifically from this implementation
Thanks!

Resources