SPesa.nim
1 import options, asyncdispatch, tables, strutils 2 import httpbeast, uri 3 from sequtils import mapIt 4 5 6 # TODO: handle USSD HTTP POST 7 # TODO: array access menu system 8 # TODO: pin-based registration system (key gen and encrypt with truncated hash of phone number and pin?) 9 # TODO: PoC Send/Receive 10 # TODO: MPESA Integration https://developer.safaricom.co.ke/docs#command-ids 11 # TODO: How to handle addresses that don't have pphone numers, make addresses first class citizen, with phone numbers attached (and have labelling) 12 13 14 # http://blog.microsave.net/2015/09/15/designing-an-effective-user-interface-for-ussd-part2/ 15 # "Geography" specific main menu 16 # Limited unbundled main menu 17 # Nesting only complementary options 18 # Customised menu based on usage history 19 # Using familiar terms 20 21 22 # https://build.at-labs.io/docs/ussd%2Foverview 23 # sessionId 24 # String A unique value generated when the session starts and sent every time a mobile subscriber response has been received. 25 # phoneNumber 26 # String The number of the mobile subscriber interacting with your ussd application. 27 # networkCode 28 # String The telco of the phoneNumber interacting with your ussd application. 29 # serviceCode 30 # String This is your USSD code. Please note that it doesn’t show your channel on shared USSD codes. 31 # text 32 # String This shows the user input. It is an empty string in the first notification of a session. After that, it concatenates all the user input within the session with a * until the session ends. 33 34 # var 35 # menu = { 0: "Send Money", 36 # 1: "Withdraw Cash", 37 # 1: "My Account", 38 # }.toTable 39 40 # # proc register() = 41 # # TODO 42 43 proc onRequest(req: Request): Future[void] = 44 # TODO: Decouple Request Handling from endpoint interface 45 if req.httpMethod == some(HttpPost): 46 let 47 uri = parseUri(req.body.get()) 48 params = uri.query.split('&').mapIt($(it.split('='))) 49 echo(req.body.get().split('&').mapIt($(it.split('=')))) 50 echo(params) 51 req.send("Hello") 52 else: 53 req.send(Http404) 54 55 when isMainModule: 56 run(onRequest, Settings(port: Port(8080), bindAddr: "")) 57