Plivo - Not receiving sms - python

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"!

Related

Twilio Outbound SMS Message Not Delivered

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.

How can I log in to my Facebook from python program without getting locked?

I am trying to send messages to Facebook friends via Messenger. I found a tutorial & tried it.
import fbchat
from getpass import getpass
username = str(raw_input("Username: "))
client = fbchat.Client(username, getpass())
no_of_friends = int(raw_input("Number of friends: "))
for i in xrange(no_of_friends):
name = str(raw_input("Name: "))
friends = client.getUsers(name) # return a list of names
friend = friends[0]
msg = str(raw_input("Message: "))
sent = client.send(friend.uid, msg)
if sent:
print("Message sent successfully!")
When I ran the program, it requested me my password. And, of course, I entered it. But Facebook doesn't accept the request from my program & lock my Facebook account. I think this is due to security reasons. Then how can I log in to my Facebook from python program without getting locked? Thanks.
This seems like the issue lies with your library, not with you. You should make a new issue at their github page. https://github.com/carpedm20/fbchat
You can selenium to remotely control the browser and do stuff a normal user can do, including logging into facebook.

When starting client the code is asking for phone/bot token

While running my first code using Telethon library, it is asking for a bot token.
This is the actual code:
from telethon import TelegramClient, events, sync
api_id = 1234567
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('anon', api_id, api_hash)
client.start()
And on command prompt:
pip3 install telethon
python3 C:/TG/First.py
Result:
Please enter your phone (or bot token)
If I give my API ID, it eventually throws the error:
telethon.errors.rpcerrorlist.PhoneNumberInvalidError: The phone number is invalid (caused by SendCodeRequest)
Why? I expect the client to start without errors.
PS: my API ID is 7 digits long.
This will only occure at your first use just enter your Phone Number starting with + then you will recive a code which you have to enter next. This is just to Authorise your Laptop beeing loged in to Telegram.
As the error message suggests, your phone number is invalid. Maybe you didn't enter it in international format?
I think you are giving your API ID, but it is asking for your phone number in international format like +91xxxxxxxxxx

I get the following error when trying to send a message to my phone number from my Twilio number

I get the following error when trying to send a message to my phone number from my Twilio number
from twilio.rest import TwilioRestClient as TRC
client = TRC('AC**********************edc','a7b***************************3d2') # connect to an account
client.messages.create(from_='+17********25', to='+23***********27', body='Twilio\'s the best!!') #create the message
Traceback
TwilioRestException: The From phone number +17*******25 is not a valid,
SMS-capable inbound phone number or short code for your account.
Can someone pls help me out?
Have you made sure to add the from_ number to your Twilio account on your Account's phone numbers page. Error 21606 may have more information regarding this issue. If this is using your "test credentials" you will want to have a look at test credentials.
The twilio number (Your from number: should be sms-enabled) that you have bought doesn't seem to have Capabilities of sending smses.

Plivo python message

I'm creating a web app in Python with Bottle which has the task to retrieve messages from Plivo. First, when I send a message to Plivo, it's like if I didn't. I can't find a Python example and I don't know much about web protocols and so on to configure all by myself.
I have the following issues which I haven't been able to fix:
1. Setting up Plivo to forward messages. In the site, you can create applications with these input options:
Application name
Sub account
Answer url
Answer method
Fallback_answer url
Fallback method
Hangup url
Hangup method
Message url
Message method
Default number app
Default endpoint app
Public uri
Setting up at least part of it should get my messages to my server. I don't know what.
2. I've got the following python code:
from bottle import route, run, request
#route('/hello', method=['GET', 'POST'])
def hello():
return "Hello World!"
bottlelog = open('bottlelog.txt').read
bottlelog.append(request + '\n')
bottlelog.close()
run(host='0.0.0.0', port=8080, debug=True)
It should save the request information in this file but at least right now it doesn't.
3. Answer. Should my server answer something specific when Plivo notifies me of my messages?
I hope that you can help me at least to find out where I should head to resolve my problems. Excuse me if I'm kind of messy, I'm new to web development and I'm just getting to know stuff.
Thank you all
Your Plivo number must be linked to an application which has a "Message url" present. When an SMS is received on your number, Plivo will send a hook to the "Message url" with the parameters Text, From, To, Type and MessageUUID. The HTTP method used to send these parameters is the "Message method" set in the application.
For the setup you described, your bottle server is listening on 8080 and has a route /hello/ open. Your Message Url should be http://<your-server-name>:8080/hello/ and the Message method should be set as POST. Click on "Create" to create your application
Next step is to link your Plivo number to the application you just created. Click on the "Numbers" tab in the dashboard. You will be able to see all your Plivo numbers under the "Your Numbers" section. By clicking on the number you'll be given an option to choose your application. Select the "Receive Message" app and click on "Update".
This sample code should get you up and running.
from bottle import run, request, HTTPResponse
#route('/hello/', method=['POST'])
def hello():
Text = request.forms.get('Text')
From = request.forms.get('From')
print "Message received: %s - by %s" % (Text, From)
return HTTPResponse(status=200)
run(host='0.0.0.0', port=8080, debug=True)
Run this code on your server and you'll be able to see the incoming messages on the console when an SMS is received on your Plivo number.

Categories