Twilio/Spoke: Does messaging service automatically share load between numbers in the service? - twilio

The Spoke app calls my Twilio Messaging Service with these parameters:
const messageParams = Object.assign(
{
to: message.contact_number,
body: message.text,
statusCallback: process.env.TWILIO_STATUS_CALLBACK_URL
},
userNumber ? { from: userNumber } : {},
messagingServiceSid ? { messagingServiceSid } : {},
twilioValidityPeriod ? { validityPeriod: twilioValidityPeriod } : {},
parseMessageText(message)
);
There is no indication as to which number in the Messaging Service to use. The Messaging Service has two numbers added to it. I tried a sample run and it sent all 6 messages to the first number added to the Messaging Service. Will it ever use the second? How can I change the policy about which number to use, apart from area code matching?

Disable sticky sender.
The Sticky Sender feature ensures the same From phone number is selected every time your application sends a message to a particular end-user. This allows your application to consistently send messages to your user from a single, recognizable phone number.

Related

Choose between Phone number and AlphaNumeric Sender Id when send SMS in Messaging Service

I added a phone number and an Alphanumeric Sender Id to a Messaging Service.
And my app has a logic to choose between sending by a Phone number or AlphaSenderId.
Could you please provide me API in Messaging Service to have the ability to choose between the Phone number and AlphaSenderId when sending an SMS?
The messaging service will pick the sender automatically based on the country you send the message to. From the doc:
If you add an Alpha Sender to your Twilio Messaging Service, Twilio will select the Alphanumeric Sender ID automatically when you send a message to a supported country, unless you also have a short code number in that same country.
I.e. you cannot influence this manually when you send a message via such an API call:
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
from: 'MG9752274e9e519418a7406176694466fa',
to: '+441632960675'
})
.then(message => console.log(message.sid));
But you could do something like this:
const useMS = false;
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
from: useMS ? 'MG9752274e9e519418a7406176694466fa' : '+441632960670',
to: '+441632960675'
})
.then(message => console.log(message.sid));

Google Home. Problem regarding configure a Lock device

Intro:
was created a Google Smart Home project
was configured a proxy server via ngrok to redirect the Google request to my local machine
I develop an IoT project that has the ability to open/close a lock. I need to implement Google integration to use the Google Assistant to control the user locks. I have implemented OAuth Server for Google. Also I have implemented some controllers to handle Google Action Intents: SYNC, QUERY and EXECUTE. Google send a request with the SYNC intent and App response a payload that contain devices list with specific settings. Instance:
{
requestId: 'requestIdOfGoogle', // contains in the request body
payload: {
agentUserId: 'userId123', // matches user id inside app system
devices: [
{
id: 1,
type: 'action.devices.types.LOCK', // device type
traits: ['action.devices.traits.LockUnlock'], // feature that has a device
name: {
name: 'Kos Lock'
},
willReportState: true,
roomHint: 'Main Door',
deviceInfo: { // Test data
manufacturer: 'smart-home-inc',
model: 'hs1234',
hwVersion: '3.2',
swVersion: '11.4'
}
}
]
}
}
Then Google send requests to my server with QUERY intent to get info about state of a devices, instance
{
requestId: 'requestIdOfGoogle', // contains in the request body
payload: {
devices: {
1: {
status: 'SUCCESS',
online: true,
isLocked: true,
// isJammed - Boolean. Whether the device is currently jammed and therefore its
// locked state cannot be determined.
isJammed: false
}
}
}
}
But after sending a response a test lock isn't configured and a user can't control one with Google Assistant.
enter image description here
I have tried to add other traits for a lock but it didn't help me. Also I have the same problem when I try to configure a Door device. But when I send to Google a Light device it works successfully. When you use the LockUnlock trait then Google Doc recommends to setup secondary user verification but it's optional.
I don't understand that do incorrect. If someone faced such a problem and solved it then could you help me, please
Prerequisites:
use node ^14.0.0
programming language - js
Touch controls are not supported for every device, and locks are not a device type that can be controlled directly. But they will still respond to voice commands.

Nexmo - Select from number based on location of destination to number

In Twilio there's an concept of phone # pools. A txt message can be sent using this Pools Id value and Twilio will select the best FROM number to send with. I've looked around Nexmos API's and I don't see similar capabilities, is this possible?
The only other option I've found is something call applications but I can't send messages without manually selecting the from numbers instead of automating it via application Id, I assume that would be one of the 'use cases'
There's a document from Nexmo https://help.nexmo.com/hc/en-us/articles/217571017-What-is-a-Sender-ID- that has the following
Random Numeric - Nexmo will apply a random number to comply with local regulations (usually taken from a pool of numbers we have access to from the relevant destination market).
Problem is how do I configure Random Numeric? It doesn't really explain and I might have missed those docs. Any suggestion help.
Random numeric is not something you set, is something the Nexmo API does in order to ensure delivery in certain parts of the world, in order to conform with local regulations.
There is no Pools concept in Nexmo at the moment, so if you want the same functionality you'd have to build it in your code. Rent a bunch of Nexmo phone numbers, and then apply a random algorithm of choice in your code before sending each message to select your phone number. Something like:
let myNexmoNumbers = [447481234567, 447481234568, 447481234569]
nexmo.message.sendSms(myNexmoNumbers[Math.floor(Math.random() * myNexmoNumbers.length)], TO_NUMBER, TEXT_MESAGE, (err, responseData) => {
if (err) {
console.log(err);
} else {
if(responseData.messages[0]['status'] === "0") {
console.log("Message sent successfully.");
} else {
console.log(`Message failed with error: ${responseData.messages[0]['error-text']}`);
}
}
})

Twilio modify sms message before forwarding using TWIML

Trying to modify a SMS message (adding a name based on the from phone number) before forwarding the message to a phone using TWIML. The phone no list is small so I will use a switch statement I am guessing in a function. I am not sure how can I wire this together w/o my own server and just using Twilio hosted stuff (TWIML, function, ?)?
Twilio developer evangelist here.
You can absolutely modify the message before forwarding it on.
If you're looking to do so without using your own server, then Twilio Functions is your best bet. Twilio Functions gives you access to a Node.js environment in which you can write functions that respond to webhooks.
To forward a message to a number but add a name based on the incoming number, you can do something like this in a function:
contacts = {
"number": "name"
}
exports.handler = function(context, event, callback) {
const name = contacts[event.From];
if (typeof name !== 'undefined') {
const message = `${name} said: ${event.Body}`;
const response = new Twilio.twiml.MessagingResponse();
response.Message({ to: YOUR_NUMBER, from: YOUR_TWILIO_NUMBER }, message);
callback(null, response);
} else {
// handle not having a name in the contacts
}
}
Check out this quick start on using Twilio Functions for more detail.

how to delete pubnub chat message history,ios

In my App there is PubNub used for Chat function,and for delete chat history,there is Web service,In app chat history clear successfully,but when application in background state and another user send message to me,notification is received and if I open that notification, it redirect to Chat Controller, but my problem is that when chat history clear successfully,still on my chat page all deleted message are present,is there is solution to delete message from pub-nub?
PubNub Message Update & Delete Features - NEW
Update Published Messages using the Message Actions feature.
pubnub.addMessageAction(
{
channel: 'chats.room123'
messageTimetoken: '15610547826970040',
action: {
type: 'updated',
value: 'Hello World! (edited)',
},
},
function(status, response) {
}
);
Delete Messages using the deleteMessages API.
There is a setting to accept delete from history requests for a key, which you must enable by checking the Enable Delete-From-History checkbox in the key settings for your key in the Admin Portal.
Requires Initialization with the secret key.
pubnub.deleteMessages(
{
channels: 'chats.room1',
start: "15526611838554309",
end: "15526611838554310",
},
function (status, response) {
console.log(status, response);
}
);
Soft Delete a Message, using the Message Actions feature.
"action": {
"type": "deleted",
"value": "."
}
UPDATE: THIS DESIGN PATTERN IS STILL LEGITIMATE BUT IS OUTDATED. PLEASE REFER TO THE ABOVE FOR BEST PRACTICES.
PubNub Storage/History Update & Delete Design Pattern
Although PubNub's API does not directly support the editing of stored messages, you can use a design pattern authored by one of our very own Solution Architects.
Message Updates and Deletes Design Pattern

Resources