Package: hangouts-helper
Hangouts Chat HelperDescriptionHelper Python classes for handling and responding to Hangouts Chat events.InstallationInstall withpip:pipinstallhangouts-helperMessage ComponentsThis library contains several component classes to assist with constructing a Hangouts Chat message.MessageSectionCardCardActionCardHeaderTextParagraphKeyValueImageButtonListImageButtonTextButtonExampleUsing thePizza Botexample from the official Hangouts Chat API documentation, this is how you'd construct the same message using the components above.fromhangouts_helper.messageimport(Message,Card,CardHeader,Section,Image,KeyValue,ButtonList,TextButton)message=Message()message.add_card(Card(CardHeader(title='Pizza Bot Customer Support',subtitle='pizzabot@example.com',image_url='https://goo.gl/aeDtrS'),Section(KeyValue(top_label='Order No.',content='12345'),KeyValue(top_label='Status',content='In Delivery')),Section('Location',Image(image_url='https://maps.googleapis.com/...')),Section(ButtonList(TextButton(text='OPEN ORDER').add_link(url='https://example.com/orders/...')))))Callingmessage.output()produces adictthat can be converted to JSON... perfect for returning a response to a synchronous chat event, or sending a new message via the Hangouts Chat API.{"cards":[{"header":{"imageUrl":"https://goo.gl/aeDtrS","subtitle":"pizzabot@example.com","title":"Pizza Bot Customer Support"},"sections":[{"widgets":[{"keyValue":{"content":"12345","topLabel":"Order No."}},{"keyValue":{"content":"In Delivery","topLabel":"Status"}}]},{"header":"Location","widgets":[{"image":{"imageUrl":"https://maps.googleapis.com/..."}}]},{"widgets":[{"buttons":[{"textButton":{"onClick":{"openLink":{"url":"https://example.com/orders/..."}},"text":"OPEN ORDER"}}]}]}]}]}Chat HandlerThe library also includes a class to help with handling incoming chat events. The methods contained inHangoutsChatHandlercorrespond to the different event types you can expect to receive. Each method should return a message response.ExamplefromenumimportEnumfromhangouts_helper.handlerimportHangoutsChatHandler,SpaceTypefromhangouts_helper.messageimportMessageclassActionMethod(Enum):BUTTON_CLICKED='BUTTON_CLICKED'classMyHangoutsChatHandler(HangoutsChatHandler):ActionMethod=ActionMethoddefhandle_added_to_space(self,space_type,event):ifspace_type==SpaceType.DM:returnMessage(text="Thanks for DM'ing me!")elifspace_type==SpaceType.ROOM:returnMessage(text="Thanks adding me to your room!")defhandle_message(self,message,event):returnMessage(text="Thanks for your message!")defhandle_card_clicked(self,action_method,action_parameters,event):ifaction_method==ActionMethod.BUTTON_CLICKED:returnMessage(text="I've processed your button click!")defhandle_removed_from_space(self,event):passA Flask app that repsonds to Hangouts Chat events might look like:fromflaskimportFlask,jsonifyapp=Flask(__name__)@app.route('/')defbot_handler():event=request.jsonhandler=MyHangoutsChatHandler()response_message=handler.handle_event(event)returnjsonify(response_message.output())TODOAdd examples for each component type in READMEDocument and add examples for adding OnClick events to widgetsDocument Enums (SpaceType,EventType,ActionMethod,Icon,ImageStyle,ResponseType)Document usage scenarios forHangoutsChatHandlerAdd methods for interacting with Hangouts Chat API toHangoutsChatHandler