RapidSMS Developers Guide/SMS & the Keyworder

From Wikibooks, open books for an open world
Jump to navigation Jump to search

It’s rapidsms message parsing library for the message resaved from route,. to use it you shod import the library from rapidsms library as:

   from rapidsms.parsers.keyworder import Keyworder

then create an instant from it :

   keyword = Keyworder ()

the Keyworder class have two important behavior; prefix, regexp the prefix behavior use to parsing the first word user sends to guide the execution path like switch statement

   keyword. Prefix = [‘help’]     

when user send message and it start with ‘help’ the interpreter will execute the code come after; the same way you call block. After satisfy the prefix we should define the expected format for the message resaved to deter main which function to call and it done by:

  @keyword(r’ the regular excretion ’) 

for example:

  @keyword(r'(\w+) (\w+) (\w+) ([0-9]+) (\w+)') 

mean after prefix handle if the string contains the exact format it will call the function on the same block which contain 5 parameter 4 word and one number on the same order For more information about regular excretion visit python document [1]

Models · Git and the Community