I'm using the following code to send an outbound SMS message from Twilio:
from twilio.rest import Client
account_sid = '<ACCOUNT SID>'
auth_token = '<AUTH TOKEN>'
client = Client(account_sid, auth_token)
message = client.messages.create(to='<To mobile number>',
from_='<Twilio phone number>',
body='Stackoverflow is awesome!')
print('Message ID: ' + message.sid)
The code worked fine for my mobile number i.e. the messages are received on my phone and the Programmable Messaging Log shows the status Delivered. All good!
However, some of my friends/colleagues couldn't receive messages on their phones. When I checked the Programmable Messaging Logs, it shows the status Sent (and not Delivered). I couldn't figure out the possible issue and a working solution to this problem.
Any guidance will be really appreciated.
The issue is resolved.
The Sent status of the messages that were not delivered eventually turned to Undelivered (Error: 30008) Unknown error. I went through this page and read about possible solutions to resolve Error 30008. Eventually, I figured out that I was using an exclamation mark (!) in the body text that was causing the problem. I removed the exclamation mark and the SMS was delivered successfully.
Related
I have a Whatsapp enabled Twilio number, but I do not receive messages from it.
message = client.messages.create(
from_='whatsapp:+1910708xxxx',
body='This is your flight confirmation for '
'IND-11 on 1/1/2022.',
to='whatsapp:+91xxxxxxxx'
However when I change the from number to the Whatsapp sandbox number, I do receive the message.
I did try to send a whatsapp message to my twilio number .. but I endup in my Messaging app inviting the number to use Whatsapp .. It is almost as if there are steps that needs to be done set Twilio number up for WA messaging ..
What am I missing ?
I think you should use your sandbox number because I found it in Twilio documentation:
The Sandbox allows you to prototype with WhatsApp immediately using a shared phone number without waiting for your Twilio number to be approved by WhatsApp.
so it means if you're unable to send Whatsapp messages from your Twilio number then it's not approved by Whatsapp yet!
I am using ejabberd in python and I found a method to send the messages but how to get them messages or receive those messages in my python console please suggest me some method or way to do this.
to send the message my code is
import xmlrpc.client as xmlrpclib
server_url = 'http://127.0.0.1:5180/xmlrpc/'
server = xmlrpclib.ServerProxy(server_url)
EJABBERD_XMLRPC_LOGIN = {'user':'yatish', 'server':'localhost', 'password':'1234', 'admin':False}
def ejabberdctl(command, data):
fn = getattr(server, command)
print(fn.__dict__,'>>>>>>>>>>')
return fn(EJABBERD_XMLRPC_LOGIN, data)
result = ejabberdctl('send_message', {"type":"chat","from":"yatish#localhost","to":"1#localhost",
"subject":"backend subject","body":"Hey this is message from python1"})
here I can send messages from yatish#localhost to 1#localhost user I want to get all the messages received of the 1#lcoalhost, can you please suggest me some method I have checked all the docs and google by my side but unable to get some ay to receive all those messages in python. if the messages received the client should connected and receive the messages relatime.
thanks
You wrote a XMLRPC client to use the ejabberd's "send_message" administrative command to perform this task.
But there isn't any admin command in ejabberd to check or read XMPP messages.
I suggest you a different approach: forget about using XMLRPC or ejabberd commands. Instead, write a small XMPP client (there are libraries in python for that, see https://xmpp.org/software/libraries/ ).
Your XMPP client should:
login to the FROM account
send the message
logout
Then write another small client that
logins to the TO account, with a possitive presence number
ejabberd will immediately send him the offline messages that were stored
do whatever with those messages, and logout
If you are able to write those XMPP clients in your prefered language (Python or whatever), you can use those clients with any XMPP server: ejabberd, or any other that you may want to install in other machines, or in the future.
I wan to make a chatbot that will automatically reply . it will collect reply from client.listen and then decide the reply to the user.
from fbchat import log, Client
# Subclass fbchat.Client and override required methods
class EchoBot(Client):
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
self.markAsDelivered(thread_id, message_object.uid)
self.markAsRead(thread_id)
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
# If you're not the author, echo
if author_id != self.uid:
self.send(message_object, thread_id=thread_id, thread_type=thread_type)
client = EchoBot("myaccount", "mypassword")
client.listen()
It worked fine until today.
Even it receive the message.the program still will stuck in client.listen
The output that i receive is this
Logging in myAccount...
Login of myAccount successful.
Listening...
When i try to contact my account , it still wont give me reply but it just stuck in client.listen
the output i wan to get is it will collect info from client.listen() and give me reply.
I believe that facebook has changed the structure of the website (id's, classes...) where fbchat library was scraping data from (Keep in mind that fbchat is not an official facebook library). This can happen with any API that is not official. I have hosted my bot 24/7 and all of sudden it stopped working. Your code is perfectly correct. From what I have tested so far I can tell that EchoBot class stopped working with all of it's event listeners, but at the other hand you can still send messages with client.send(...) We can only hope that developers of fbchat library will fix this soon.
See here for more info: https://github.com/carpedm20/fbchat/issues/483
2020 UPDATE
The issue was fixed in new version of fbchat 1.9.6.
Just update the module with:
pip install fbchat --upgrade
I've just started using Plivo to set up an sms service. I'm trying to receive SMSs on my server but my server just doesn't seem to receive them.
I've set it up on heroku, the below is my code:
import plivo, plivoxml
import os
import os.path
from flask import Flask, request
app = Flask(__name__)
#app.route("/receive-sms/",methods=['GET','POST'])
def inbound_sms():
# Sender's phone number
from_number = request.values.get('From')
print from_number
# Receiver's phone number - Plivo number
to_number = request.values.get('To')
# The text which was received
text = request.values.get('Text')
params = {
"src": to_number,
"dst": from_number,
}
body = "Thanks, we've received your message."
# Generate a Message XML with the details of
# the reply to be sent.
r = plivoxml.Response()
r.addMessage(body, **params)
return r.to_xml()
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
# print port
app.run(host='0.0.0.0', port=port)
On Plivo, my message url is:
http://ripmac.herokuapp.com/receive-sms/
I've linked my Plivo number to the right plivo application.
Additionally, I'm not sure if I'm supposed to see messages when I login on Plivo and navigate to the logs->SMS. There are no logs which is starting to make me think that there is something wrong with the port/message url. Any help will be much appreciated. Thanks!
I'm new as well and was having the exact problem as the poster above me. I was looking through their documentation and i found this:
"Note: If you are using a Plivo Trial account for this example, you can only send sms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page."
Once i added my phone number, it worked.
One more thing: when i filled out the form to verify the number, i noticed it would not validate with [area code]number. The other thing i made sure i did was send the number in the format [CountryCode][Area Code] Number
My experience.
I bought a Plivo US number.
I setup the Application with "Message URL" but my server was never hit when I tried to send an SMS from an IT or a UK number.
I tried to call using the UK number and I found the log for missing "Hangup URL" in SMS/Logs/Debug.
With the helpdesk we tried to send SMS from a US numbers. It works.
I haven't read about any limitation for the SMS source country and also the help desk didn't says nothing about it in the ticket (I explained everything precisely).
So, that's it. A US number cannot receive SMS from a non-US number. (but apparently calls work). I also tried to receive a verification code from PayPal US and this does not work too.
The help desk guy suggested me to buy a UK number for SMS from UK, but they don't sell UK numbers if you select "SMS"!
My system has about 10000 iOS users and i want to send them a push notification but without taking time as i may send another message after 5 minutes or less for the same user,
I read this answer before which also founded in Apple Site:
Push Notification Throughput and Error Checking
There are no caps or batch size limits for using APNs. The iOS 6.1
press release stated that APNs has sent over 4 trillion push
notifications since it was established. It was announced at WWDC 2012
that APNs is sending 7 billion notifications daily.
If you're seeing throughput lower than 9,000 notifications per second,
your server might benefit from improved error handling logic.
But a don't know how to send 9000/s message while i'm sending the notification one by one.
I'm using Python (PyAPNs) and this is my code:
from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
for row in result:
token_hex = row['token_hex']
apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
payload = Payload(alert="Message",badge=1,sound='default')
apns.gateway_server.send_notification(token_hex, payload)
I'm sending to 10000 users in more than 30 minutes...
So what is the problem in my code or what can i do to send the notification in less time...
Thanks in Advance,
I don't know python but looking at your code it looks like you are duplicating calls unnecessarily. You should use the same connection for sending all the notifications.
Perhaps you should try something like this :
from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
payload = Payload(alert="Message",badge=1,sound='default')
for row in result:
token_hex = row['token_hex']
apns.gateway_server.send_notification(token_hex, payload)
This is assuming you are sending the same notification payload to all your devices.