How to obtain final STATUS from a text sent to mobile phone - twilio

I am sending a text to a mobile number (US phone number) using the Programmable Messaging Quickstart for C# with .NET Core example. The message is sent and received successfully but the STATUS in the response shows "queued".
Is there a sample callback in C# to obtain the final status after the text is sent?

You have 3 options, either of the first two are suggested.
Subscribe to statusCallbacks, which will alert your application of the delivery status of the send message.
Use Event Streams to subscribe to specific message delivery event types (this option provides the ability to select different types of message delivery events).
Less efficient and not very scalable, make a request to the /Messages endpoint to determine the final disposition of the sent message (via its unique message SID).
Best Practices for SMS Message Logging

Related

WhatsApp chats real time recording

I have requirement from compilance to backup my business WA users chats (for reasonable price...)
Ive googled a lot and seems (correct me if Im wrong) only solution is to build own chat app (or use app delivered by API provider)
I've checked eg twilio, 360dialog, chat-api
I played a bit witch twilio and I know how to save incoming messages (sent by eg client), but not outgoing (sent by my users)
Also I know how to send WA msgs from my own app (so I can record those)
But my preference would be users to use WA on mobile phones or WA web and listen some hooks to record that.
Any idea how to implement that? Maybe WA buisness API can do that?
There is no straight way to do this using WhatsApp Business APIs,
You need to record both the messages in one place/table/collection whether it is sent from our business phone number or received from the clients/users.
We can do it but have to use proper logic, let's see both the scenario and how to record it in one place/table/collection,
Send Message from WhatsApp Business API (from our business phone number) to clients/users:
You can record the message whenever Business sends any message to clients/users because Webhook does not give that sent message content, yes it will notify us about status updates like sent, delivered, read, failed, etc.
Things we can record:
Message ID (This is important, you will get in response whenever we send a message from Business API)
From Phone Number (Business phone number)
Message Content
To Phone Number (Client/user phone number)
Message Status (sent, read, delivered, failed)
Sent Date
Updated Date (updated message status date)
Type (from business)
Receive Messages from clients/users to our Business Phone Number:
You can get message content from Webhook, so we can record that received message content object in our table/collection,
Things we can record:
Message ID (This is important, Get in Webhook)
From Phone Number (Client/User phone number)
Message Content
To Phone Number (Business phone number)
Message Status (sent, read, delivered, failed)
Sent Date (message received date)
Updated Date (updated message status date)
Type (from user/client)
Other Things that I am not sure about:
We can't get message content If a Business phone number sends a message to a client/user from WhatsApp Business App.

Broadcast to only one web socket in room using ActionCable

I am using ActionCable to provide Browser Notification which is easy to implement. The problem is coming when a user has open the multiple tabs in the browser and I need to send the data to only one tab i.e to only one WebSocket in user room. How can this be done?
Isolating a single pub/sub client isn't directly possible with the pub/sub approach, because the whole idea is that publishers have no knowledge of subscribers.
However, there are two common ways to solve this:
to use a different named channel per connection, saving the named channel in the database and forwarding all messages to that specific named channel (i.e. saving the channel user-ID-TIMESTAMP in the database and using it as the target connection).
another, somewhat more reliable approach (though more complex) is to send the message to all clients but create a race condition that allows only a single client to receive the actual message. This would look something like this:
server sends "you have a message" to all clients.
client polls "undelivered" messages from the server.
server locks the message pool or uses a database transaction in order to retrieve undelivered messages and mark the messages as delivered. The server sends the undelivered messages to the client (optionally setting an ACK timeout).
a single client connection receives the undelivered messages the rest get an empty array of messages (since they were all delivered to the other client) or receive a "delivered" flag so the data is updated but no notification is raised.
(optional) the client sends and ACK.
(optional) the server marks the message delivery as complete. If no ACK was received before "timeout", server unmarks delivery and resends the "you have a message" message.
Good luck!
Every time a new connection is made we will create a new room. So for example when the user is making a new connection we can give the room name as users:user_id:some_unique_random_string which may be equal to users:user_id:123j123b1h2b1j23bh12b3 and when the same user makes another connection by opening another tab we will also do the same and create a separate room.
Now one thing the ActionCable provides is that we can find all the room name followed by any prefix.
Lets the user has made three connections and their rooms are users:128:123n1jh123ko9876, users:128:asdas23412cs1234, users:128:asni9202h5i3jens then we can obtain these room name using ActionCable also.
user_id = 128
pubsub = ActionCable.server.pubsub
channel_with_prefix = pubsub.send(:channel_with_prefix, RoomChannel.channel_name)
channels = pubsub.send(:redis_connection).pubsub('channels', "#{channel_with_prefix}:users:#{user_id}:*")
Now the channels is an array consisting of the rooms name.
So puts channels
["chatapp_production:users:128:123n1jh123ko9876", "chatapp_production:users:128:asdas23412cs1234", "users:128:asni9202h5i3jens"]
This is how we can find all the rooms related to a single user without using any external database and API calls.

How to send message in a thread using microsoft graph API?

I'm building a tool in which I need to send more than 2 messages in the same thread (the message have identical subject & recipients) using Microsoft Graph API with some interval of days between them.
The problem is that I cannot send a message in the same thread using the API, even though the subject & recipients are same, Outlook displays them as different threads (but on the recipients' side (Gmail side) - they belong to same thread).
I tried using conversationId (which I got in the first message) in the second message but they still ended up showing in different threads.
Is there any way in I can send messages in the same thread?
According to your description, I assume you want to use the https://graph.microsoft.com/v1.0/groups/{id}/threads endpoint to send more than 2 messages in the same thread.
Refer to this document,
A new conversation, conversation thread, and post are created in the group. Use reply thread or reply post to further post to that thread.
So we can use the replay endpoint to send message in the same thread.
To send emails in one thread you should use createReply method where you provide messageId of a previously sent message.
The tricky part is that after you sent a message with send or sendMail API methods, you do not have access to messageId. Even if you create a message via create method, messageId will be different after sending it.
So the solution is to send the message and find it in 'Sent Items' folder to retreive messageId. I am doing this based on time, subject and receiver. There is also useful param $top.
With correct messageId you'll be able to create reply and send it in the same thread.

Twilio Studio: send response message based on incoming message content

I already have a Twilio application with this use case :
The incoming message is forwarded to a client
The client replies to the message by sending a message to the twilio number. The message body will contain the phone number at the beginning followed by the message content.
The web hook checks if the message is received from the client and it contains a phone number. If so, it forwards the message to the phone number in the body.
I would like to implement this use case using Twilio studio.
Is this possible?
You can use the Split widget and use a regular expression to test whether the input from Step 2 contains a phone number or not.

Sending notification or SMS in response to an event Xcode

In Xcode I want to make an app that when a certain condition is met, it will send an SMS to a predefined contact.
I am aware this is not directly possible, but what are the alternatives to make this happen?
It should send without confirmation to a pre-defined contact you have selected and have a pre-defined message
very simple: when event happen , your handler (IBAction method) sent a message to your server (e.g. web service) to send this pre-defined message.

Resources