Skip to content

Commit bad85b8

Browse files
authored
Merge pull request #118 from HaripriyaB/send_message_textbelt
Send text message using TextBelt API to any phone number
2 parents 21a4279 + 31eaa21 commit bad85b8

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Send Text Message via TextBelt
2+
### Description
3+
The aim is to anonymously send a text message to a mobile number programmatically.
4+
5+
### Library used
6+
* [requests](https://2.python-requests.org/en/v2.7.0/)
7+
8+
### About TextBelt API:
9+
*Textbelt* is an SMS API that is built for developers who just want to send and receive SMS. Sending an SMS is a simple thing. The API is correspondingly simple, without requiring account configuration, logins, or extra recurring billing.
10+
11+
The `https://textbelt.com/text` endpoint accepts a POST request with the following parameters:
12+
13+
* `phone`: A phone number. If you're in the U.S. or Canada, you can just send a normal 10-digit phone number with area code. Outside the U.S., it is best to send the phone number in E.164 format with your country code.
14+
* `message`: The content of your SMS.
15+
* `key`: Your API key (use textbelt to send a free message).
16+
17+
Every programming language has a way to send an HTTP POST request. Instead of installing a special Textbelt library, just send a POST request.
18+
19+
*Response*
20+
21+
The /text endpoint will respond with JSON:
22+
* `success`: Whether the message was successfully sent (true/false).
23+
* `quotaRemaining`: The amount of credit remaining on your key.
24+
* `textId`: The ID of the sent message, used for looking up its status. Only present when success=true. Use this to check SMS delivery status.
25+
* `error`: A string describing the problem. Only present when success=false.
26+
27+
### Parameters used and their Significance:
28+
* phoneNumber : The 10 digit phone number given by the user.
29+
* message : The message which the user wants to sent to the given phoneNumber.
30+
31+
### Pre-requisites:
32+
Install requests library via pip/pip3
33+
34+
`>> pip3 install requests`
35+
36+
### Usage:
37+
`>> python send_message.py`
38+
39+
### I/O:
40+
41+
```
42+
Enter your 10 digit phone number: $(phone_number)
43+
44+
Enter your message: $(message)
45+
46+
Message successfully sent!
47+
```
48+
49+
<img src="ScreenShots/output.png" height=50 width=300>
50+
</br></br>
51+
<img src="ScreenShots/message_received.jpg" height=200 width=100>
52+
53+
54+
**OR (if sending failed)**
55+
56+
```
57+
Sorry...Message cannot be sent
58+
Only one test text message is allowed per day.
59+
```
Loading
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import requests
3+
4+
def send_message(phoneNumber, message):
5+
resp = requests.post('https://textbelt.com/text', {
6+
'phone':phoneNumber,
7+
'message':message,
8+
'key':'textbelt',
9+
})
10+
sent = resp.json()['success']
11+
if sent is True:
12+
print("Message successfully sent!")
13+
14+
else:
15+
print("Sorry...Message cannot be sent")
16+
print(resp.json()['error'])
17+
18+
def main():
19+
phone_number = input("Enter your 10 digit phone number: ")
20+
message = input("Enter your message:")
21+
send_message(('+91'+str(phone_number)),message)
22+
23+
if __name__ == "__main__":
24+
main()
25+

0 commit comments

Comments
 (0)