So below is an example in Python on how your bot can extract arguments from a Symphony chat message.
@activities.slash("/echo {first_string_argument} {second_string_argument}")
async def on_echo_string_arguments(context: CommandContext):
#Get string argument with get_string
first_string_argument = context.arguments.get_string("first_string_argument")
# Get string argument with get_as_string
second_string_argument = context.arguments.get_as_string("second_string_argument")
message = f"Received arguments: {first_string_argument} and {second_string_argument}"
await messages.send_message(context.stream_id, f"<messageML>{message}</messageML>")
In the example we are just returning the values back to the user in the form of a Symphony message. But you could invoke your own business logic (including a Selenium web driver class) to carry out another action.
Here is a full example which may help also referenced from the same page shared previously.
from symphony.bdk.core.activity.command import CommandContext
from symphony.bdk.core.config.loader import BdkConfigLoader
from symphony.bdk.core.symphony_bdk import SymphonyBdk
async def run():
async with SymphonyBdk(BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk:
activities = bdk.activities()
messages = bdk.messages()
@activities.slash("/buy {$ticker} {quantity}")
async def on_echo_mention(context: CommandContext):
ticker = context.arguments.get_cashtag("ticker").value # can also be retrieved with context.arguments.get("ticker").value
quantity = context.arguments.get_string("quantity")
message = f"Buy ticker {ticker} with quantity {quantity}"
await messages.send_message(context.stream_id, f"<messageML>{message}</messageML>")
May I ask a follow-up question?
If the case is:
Person A has said /buy {$ticker} {quantity}
1 minute ago and 1 hour ago respectively, and I want to open this bot to execute only the command for the request 1 minute ago (since I have executed the command for the 1 hour ago request already), can this be done?
Thank you