Skip to content

Instantly share code, notes, and snippets.

@jamalex
Created March 16, 2017 22:55
Show Gist options
  • Save jamalex/6186168f0eb3260657916afe3f3e07eb to your computer and use it in GitHub Desktop.
Save jamalex/6186168f0eb3260657916afe3f3e07eb to your computer and use it in GitHub Desktop.
import smpplib2.gsm
import smpplib2.client
import smpplib2.consts
import smpplib2.exceptions
# TODO: update these based on the address/credentials for the SCSM server
SMSC_ADDRESS = '127.0.0.1'
SMSC_PORT = 1234
SMSC_SYSTEM_ID = 'pavel'
SMSC_PASSWORD = 'wpsd'
# TODO: what should the source address be?
SOURCE_ADDRESS = '11111111'
# TODO: what should the TON and NPI values be?
SOURCE_ADDR_TON = smpplib2.consts.SMPP_TON_INTL
SOURCE_ADDR_NPI = smpplib2.consts.SMPP_NPI_ISDN
DEST_ADDR_TON = smpplib2.consts.SMPP_TON_INTL
DEST_ADDR_NPI = smpplib2.consts.SMPP_NPI_ISDN
# TODO: Probably needs to be translated for each country?
SMS_MESSAGE_TEMPLATE = 'Your Instant Schools password has been reset; the new temporary password is: %s'
def send_temporary_password(phone, password):
parts, encoding_flag, msg_type_flag = smpplib2.gsm.make_parts(SMS_MESSAGE_TEMPLATE % password)
try:
client = smpplib2.client.Client(SMSC_ADDRESS, SMSC_PORT)
client.connect()
except smpplib2.exceptions.ConnectionError:
raise Exception("Unable to connect to SMSC server %s:%s" % (SMSC_ADDRESS, SMSC_PORT))
client.bind_transceiver(system_id=SMSC_SYSTEM_ID, password=SMSC_PASSWORD)
for part in parts:
pdu = client.send_message(
source_addr_ton=SOURCE_ADDR_TON,
source_addr_npi=SOURCE_ADDR_NPI,
source_addr=SOURCE_ADDRESS,
dest_addr_ton=DEST_ADDR_TON,
dest_addr_npi=DEST_ADDR_NPI,
destination_addr=phone,
short_message=part,
data_coding=encoding_flag,
esm_class=msg_type_flag,
registered_delivery=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment