async def receive(self, text_data): """Handle event of received message.""" action = json.loads(text_data) action_type = re_camel_case.sub( r'_\1', action['type']).strip('_').lower().split('/')[-1] await self.channel_layer.send( self.channel_name, { 'type': action_type, # Specify event type using callback. 'payload': action['payload'], # Set value for using callback. })
def camel_to_snake_case(value): """ Splits CamelCase and converts to lower case with underscores. """ return re_camel_case.sub(r"_\1", value).strip("_").lower()