Package: sainofirst
Sainofirst SDKThe Sainofirst SDK for python provides a python API for Sainofirst services. You can use the python API to build libraries or applications for python.Using the SDK for python makes it possible to realize a number of compelling use cases. their are several things you can build by using the SDK for python.Setting Up the SDK for PythonInstalling the SDKThe preferred way to install the Sainofirst SDK for python is to use thepippackage manager for python.Go to your python project directory.cdyour_project_directoryThen simply type the following into a terminal windowpip3installsainofirstThis will install the Sainofirst SDK into your python project.Loading the SDKAfter you install the SDK, you can load the Sainofirst SDK in your python application using import.fromsainofirstimportSainofirstConfigure Your CredentialsYou need to provide credentials to Sainofirst SDK so that only your account and its resources are accessed by the SDK. For more information about obtaining your account credentials, seeGetting Your Credentials.To hold this information, we recommend you create an environment variable with SAINOFIRST_API_KEY as it's key and it's value should hold your Sainofirst api key.SAINOFIRST_API_KEY=your_sainofirst_api_keyAlternatively if you prefer you can set your credentials directly in code (NOT RECOMMENDED)We do not recommend hard coding your Sainofirst credentials in your scripts. Hard coding credentials poses a risk of exposing your api key.sf=Sainofirst("YOUR API KEY")Working with Sainofirst SDKThe Sainofirst SDK for python provides access to services that it supports through a collection of service instances. Each supported Sainofirst service offer low-level APIs for using service features and resources.The services exposed through the SDK for python follow the request-response pattern to exchange messages with calling applications. In this pattern, the code invoking a service submits an HTTP/HTTPS request to an endpoint for the service. The request contains parameters needed to successfully invoke the specific feature being called. The service that is invoked generates a response that is sent back to the requestor. The response contains data if the operation was successful or error information if the operation was unsuccessful.Not all services are immediately available in the SDKList of current services available under this version of SDKsmsvoiceWhen using the SDK for python, you add the SDK package to your application using import, which provides support for all current services.Accessing Sainofirst  Servicesimporting the SDK for python as shown previously includes the entire SDK into your code.fromsainofirstimportSainofirstBegin by creating an instance of the Sainofirst SDK and assign it to a variable.sf=Sainofirst()To access service features through the Sainofirst class, you first access a service through which you access a set of features provided by the underlying service instance. Generally there is one service instance provided for each service.Consider the following code used to access sms servicesms=sf.smsAccessing Individual  ServicesTo access individual service begin by importing that servicefromsainofirst.services.smsimportSmscreating an instance of the service and assign it to a variable.sms=Sms()Sms ServiceProgrammatically send high volumes of text messages globally. Your users can get OTP, alerts, stock prices, account balance, transaction statements, discounts, offers and much more all over a message.Sainofirst sms service provides easy api for sending and scheduling text messages which you can easily integrate in your python application.Required configuration options for sms serviceoptiontypedescriptionsenderidStringThe registered and approved Sender name.routeStringType of connectivity ex Global, Promotional, Transactional, etc.Using sms serviceBegin by loading Sainofirst SDK into your python project.fromsainofirstimportSainofirstCreate a new instance of Sainofirst SDK. Make sure you have configured your apikey in environment variable.sf=Sainofirst()Access sms service from the SDK.sms=sf.smsAlternatively if you do not want to load whole sdk you can also access individual services. To access individual service begin by importing that servicefromsainofirst.services.smsimportSmsCreate an instance of the service and assign it to a variable. Make sure you have configured your apikey in environment variable.sms=Sms()Define a callback function which will get executed after recieving response from Sainofirst server.defcallback(success,error):iferror!=None:raiseException(error)print(success)Sending a text messageYou can easily send text message by setting your text message using message method, list of numbers by using numbers method and setting required options using set method and then calling send method along with callback(sms.message("your text message here").numbers(["91888xxxxx","918323xxxx"]).set({"senderid":"SAIFST","route":"Transactional"}).send(callback))Scheduling a text messageUse schedule method to schedule your text message(sms.message("your text message here").numbers(["91888xxxxx","918323xxxx"]).schedule("2020-11-03 15:40:05").set({"senderid":"SAIFST","route":"Transactional"}).send(callback))Sending a message in any languageIf you want to send text message in any language you will have to configure an additional optionunicodeto 1optiontypedescriptionunicodeNumberMessage can be send in any language ( Values 1 or 0 )(sms.message("your text message here").numbers(["91888xxxxx","918323xxxx"]).set({"senderid":"SAIFST","route":"Transactional""unicode":1}).send(callback))Sending a flash messageIf you want send a flash message set additional optionflashto 1optiontypedescriptionflashNumberSend flash SMS( Values 1 or 0 )(sms.message("your text message here").numbers(["91888xxxxx","918323xxxx"]).set({"senderid":"SAIFST","route":"Transactional""flash":1}).send(callback))Sending multiple message with same configuration optionsYou can send multiple message with same configuration optionssms.set({"senderid":"SAIFST","route":"Transactional""unicode":0"flash":0})(sms.message("your text message 1").numbers(["91888xxxxx","918323xxxx"]).send(callback))(sms.message("your text message 2").numbers(["91888xxxxx","918323xxxx"]).send((lambdasuccess,error:print(success)ifsuccess!=None)))(sms.message("your text message 3").numbers(["91888xxxxx","918323xxxx"]).send(callback))Getting request dictionaryGet request dictionary by using get methodrequestDictionary=(sms.message("your text message here").numbers(["91888xxxxx","918323xxxx"]).set({"senderid":"SAIFST","route":"Transactional""unicode":0"flash":0}).get())Alternate way to use sms service using send methodAdditional optionsnumberandmessageare required while sending request dictionary directly using send methodoptiontypedescriptionnumberList[String]List of number with country prefix. (multiple numbers can be separated by comma.)messageStringSMS text body. The actual message.Sending text messageYou will need to setmessageto your text body andnumberto a list containing numbers you want your message to get delivered to.sms.send({"senderid":"SAIFST","route":"Transactional""number":["86983xxxxx","728737xxxx"],"message":"your text message"},callback)Schedule a messageSchedule a message by using additional configuration optiontimeoptiontypedescriptiontimeStringSchedule time (in format i.e, yyyy-mm-dd hh:mm:ss) at which the SMS has to be sentsms.send({"senderid":"SAIFST","route":"Transactional""number":["86983xxxxx","728737xxxx"],"message":"your text message","time":"2020-11-03 23:11:04"},callback)Sending a message in any languageIf you want to send text message in any language you will have to configure an additional optionunicodeto 1optiontypedescriptionunicodeNumberMessage can be send in any language ( Values 1 or 0 )sms.send({"senderid":"SAIFST","route":"Transactional""number":["86983xxxxx","728737xxxx"],"message":"your text message","unicode":1},callback)Sending a flash messageIf you want send a flash message set additional optionflashto 1optiontypedescriptionflashNumberSend flash SMS( Values 1 or 0 )sms.send({"senderid":"SAIFST","route":"Transactional""number":["86983xxxxx","728737xxxx"],"message":"your text message","flash":1},callback)Voice ServiceProgrammatically send voice calls and build conversations anywhere and everywhere. Make calls around the world. Your users can get OTP, alerts and much more all over a call.Sainofirst voice service provides easy api for making and scheduling phone calls which you can easily integrate in your python applications.Required configuration options for voice serviceoptiontypedescriptionsubscription_idNumberPricing and Routes will be based on this ID. The value of this ID can be accessed from the SainoFirst's Application under connectivity. If subscription not assigned please contact your account manager.maxLengthOfCallNumberLimits the call duration to this much seconds, the call will be disconnected after this much second automatically even if receiver is not cutting the call.(Value In Second)Using voice serviceBegin by loading Sainofirst SDK into your python project.fromsainofirstimportSainofirstCreate a new instance of Sainofirst SDK. Make sure you have configured your apikey in environment variable.sf=Sainofirst()Access voice service from the SDK.voice=sf.voiceAlternatively if you do not want to load whole sdk you can also access individual services. To access individual service begin by importing that servicefromsainofirst.services.voiceimportVoiceCreate an instance of the service and assign it to a variable. Make sure you have configured your apikey in environment variable.voice=Voice()Define a callback function which will get executed after recieving response from Sainofirst server.defcallback(success,error):iferror!=None:raiseException(error)print(success)Making an audio callTo make an audio call set url to the audio file by usingaudiomethod and list of numbers by usingnumbersmethod. Configure required options usingsetmethod and execute asendmethod with a callback function(voice.audio("audio_file_url").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,}).send(callback))Making text synthesized voice callIf you want to make text synthesized voice call you will be required to configure two additional optionsspeech_rateandlanguage_idalong with setting text usingtextmethodoptiontypedescriptionspeech_rateNumberminimum 0.5 - maximum 2 (Lower the value, Slower the speed of voice audio converted via text-to-speech synthesis )language_idNumberLanguage ID of the text to be converted via Text-to-Speech synthesis.(voice.text("your message").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,}).send(callback))Scheduling a voice callUseschedulemethod to schedule a callScheduling an audio call(voice.audio("audio_file_url").numbers(["91888xxxxx","918323xxxx"]).schedule("2020-11-03 15:40:05","Asia/Kolkata (GMT +05:30)").set({"subscription_id":26236,"maxLengthOfCall":14,}).send(callback))Scheduling text synthesized call(voice.text("your message").numbers(["91888xxxxx","918323xxxx"]).schedule("2020-11-03 15:40:05","Asia/Kolkata (GMT +05:30)").set({"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,}).send(callback))Rescheduling a voice callIf you want to reschedule an already scheduled voice call usereschedulemethod with following options.optiontypedescriptionvoice_idNumberUnique ID which was received in response while sending the voice call.new_send_atStringSchedule time (in format i.e, yyyy-mm-dd hh:mm:ss) at which the SMS has to be senttimezoneStringtimezone refers to the local time of a region or a countryvoice.reschedule({"voice_id":7878,"new_send_at":"2020-11-03 15:40:05","timezone":"Asia/Kolkata (GMT +05:30)"},callback)Cancelling a scheduled voice callYou can cancel already scheduled call by providing voice id which was received in response while making a voice call.voice.cancel(7878,callback)Making advanced voice callAdvanced voice call  is the voice call where Listener (or Receiver) will be able to interact even with the simple pre-recorded or text-to-speech voice call.Features in Advance voice call:Repeat the same voice message again on press of 'Assigned' key.Forward the call to some other (predefined) number on press of 'Assigned' key.Theconfigoption is used to make a advanced voice call. It further has two optionsoptiontypedescriptionrepeatNumberValue must be a single digit number. On press of this number key, the call will be repeated.callTransferDictUse to configure call transfercallTransferis used to do a call transfer on press of a key. It has two optionoptiontypedescriptiontransferKeyNumberOn press of this key, call will be forwarded.transferNumberNumberNumber on which call to be forwarded.Advanced audio call(voice.audio("audio_file_url").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,"config":{"repeat":0,"callTransfer":{"transferKey":4,"transferNumber":8798190000}}}).send(callback))Advanced text synthesized voice call(voice.text("your message").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,"config":{"repeat":0,"callTransfer":{"transferKey":4,"transferNumber":8798190000}}}).send(callback))Getting request dictionaryUsegetmethod to get request dataGet request data for audio voice callrequestData=(voice.audio("audio_file_url").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,}).get())Get request data for text synthesized voice callrequestData=(voice.text("your message").numbers(["91888xxxxx","918323xxxx"]).set({"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,}).get())Alternate way to use voice service using send methodAdditional optionsnumbersandis_textare required while sending request dictionary directly using send methodoptiontypedescriptionnumbersList[String]Array of String of numbers.is_textBooleanSet this to true for sending text-to-speech based voice call.Making an audio callUseaudio_file_urloption to provide audio file url while making an audio calloptiontypedescriptionaudio_file_urlStringURL of audio file that will be played on voice call.voice.send({"is_text":False,"numbers":["8699xxxxxx","9435xxxxxx"],"subscription_id":26236,"maxLengthOfCall":14"audio_file_url":"your audio file url",},callback)Making a text synthesized voice callTo make a text synthesized voice call you will be required to provide following options along with required options.optiontypedescriptiontextStringThe actual text that would be converted to voice by Text-to-Speech synthesis and will be played over Voice call.speech_rateNumberminimum 0.5 - maximum 2 (Lower the value, Slower the speed of voice audio converted via text-to-speech synthesis )language_idNumberLanguage ID of the text to be converted via Text-to-Speech synthesis.voice.send({"is_text":True,"numbers":["8699xxxxxx","9435xxxxxx"]"subscription_id":26236,"maxLengthOfCall":14,"text":"your text message here","speech_rate":1,"language_id":0},callback)Scheduling a voice callIf you want to schedule a voice call setsend_atto time at which you want to schedule a call and you will also be required to provide atimezoneoptiontypedescriptionsend_atStringSchedule time (in format i.e, yyyy-mm-dd hh:mm:ss) at which the SMS has to be senttimezoneStringtimezone refers to the local time of a region or a countryScheduling audio callvoice.send({"is_text":False,"audio_file_url":"your audio file url","numbers":["8699xxxxxx","9435xxxxxx"],"subscription_id":26236,"maxLengthOfCall":14,"send_at":"2020-11-03 15:40:05","timezone":"Asia/Kolkata (GMT +05:30)"},callback)Scheduling text synthesized voice callvoice.send({"is_text":True,"text":"your text message here","numbers":["8699xxxxxx","9435xxxxxx"]"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,"send_at":"2020-11-03 15:40:05","timezone":"Asia/Kolkata (GMT +05:30)"},callback)Making advanced voice callTheconfigoption is used to make a advanced voice call. It has two properties.optiontypedescriptionrepeatNumberValue must be a single digit number. On press of this number key, the call will be repeated.callTransferDictUse to configure call transfercallTransferis used to do a call transfer on press of a key. It has two propertiesoptiontypedescriptiontransferKeyNumberOn press of this key, call will be forwarded.transferNumberNumberNumber on which call to be forwarded.Advanced audio callvoice.send({"is_text":False,"audio_file_url":"your audio file url","numbers":["8699xxxxxx","9435xxxxxx"],"subscription_id":26236,"maxLengthOfCall":14,"config":{"repeat":0,"callTransfer":{"transferKey":4,"transferNumber":8798190000}}},callback)Advanced text synthesized voice callvoice.send({"is_text":True,"text":"your text message here","numbers":["8699xxxxxx","9435xxxxxx"]"subscription_id":26236,"maxLengthOfCall":14,"speech_rate":1,"language_id":0,"config":{"repeat":0,"callTransfer":{"transferKey":4,"transferNumber":8798190000}}},callback)