blob: 8e3027e7b0af0ef0c2f01d3a64d96e5105e7a7a5 [file] [log] [blame]
'''
Example Action feed for Google Order Redirect.
'''
import json
from generated import action_pb2
from google.protobuf.json_format import MessageToDict
def create_feed() -> str:
# Create ActionFeed
feed = action_pb2.ActionFeed()
# Create ActionDetail by passing fields to the constructor
# Example using the same link for delivery and takeout
action_detail_combined = action_pb2.ActionDetail(
entity_id='merchant-1',
link_id='merchant-1-takeout-delivery-action',
url='http://provider.com/merchant-1',
actions=[
action_pb2.Action(
food_ordering_info=action_pb2.FoodOrderingInfo(
service_type=action_pb2.FoodOrderingInfo.ServiceType.DELIVERY
)
),
action_pb2.Action(
food_ordering_info=action_pb2.FoodOrderingInfo(
service_type=action_pb2.FoodOrderingInfo.ServiceType.TAKEOUT
)
)
]
)
# Add ActionDetail to data
feed.data.append(action_detail_combined)
# Example using separate link for delivery
action_detail_delivery = action_pb2.ActionDetail(
entity_id='merchant-2',
link_id='merchant-2-delivery-action',
url='http://provider.com/merchant-2/delivery',
actions=[
action_pb2.Action(
food_ordering_info=action_pb2.FoodOrderingInfo(
service_type=action_pb2.FoodOrderingInfo.ServiceType.DELIVERY
)
)
]
)
# Add ActionDetail to feed data
feed.data.append(action_detail_delivery)
# Serialize feed to JSON string
return json.dumps(MessageToDict(feed, preserving_proto_field_name=True))
feedJSON = create_feed()
print(feedJSON)