This week I have been mainly working on my Capstone project Teams bot.
In terms of the progress made, I have:
- Attempted to make proactive messaging, but put on hold due to failure (most likely due to missing Azure Registration and true Teams compatibility)
- Learned how to create adaptive cards
- Used API to send random Pokemon image upon request
#TEMPORARILY ON HOLD (WILL TRY WITH AZURE REGISTRSTION)
"""@app.on_message_pattern(re.compile(r"remind"))
async def handle_proactive_message(ctx:ActivityContext[MessageActivity]) -> None:
# Use the standard from_.id for consistency
user_id = ctx.activity.from_.id
storage[user_id] = ctx.activity.conversation.id
await ctx.send("Okay")
scheduler.add_job(
send_proactive_notification,
'date', # Use 'date' for a one-time reminder in 10s
run_date=datetime.now() + timedelta(seconds=10),
args=[user_id],
id=f"remind_{user_id}",
replace_existing=True
)
async def send_proactive_notification(user_id: str):
conversation_id = storage.get(user_id)
if not conversation_id:
print(f"DEBUG: No conversation found for {user_id}") # Check your console!
return
# Required: Proactive messages often need an explicit recipient account
activity = MessageActivityInput(text="I'm reminding u bro").with_recipient(Account(id=user_id))
await app.send(conversation_id, activity)"""
Above is the code for the proactive messaging which is on hold due to lack of proper integration into Microsoft Teams.
@app.on_message_pattern(re.compile(r"image|sendimage|imagepls"))
async def handle_image_request(ctx: ActivityContext[MessageActivity]) -> None:
"""send image as adaptive card"""
num = random.randint(1,1025)
card = AdaptiveCard(
body=[
Image(
url=f"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{num}.png",
size="Large",
alt_text="ditto"
)
]
)
await ctx.send(card)
Above is the code to send adaptive card with a random pokemon image.
Leave a Reply