Last active
May 4, 2023 14:11
-
-
Save fedme/a753cc1fe09f9b1c639a5174f839888c to your computer and use it in GitHub Desktop.
Process any kind of message in Stacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example Stack that shows how to process every possible WhatsApp message type | |
# This is still under development and the syntax might change before it's finalized and | |
# published in our docs. | |
card Start, then: ProcessResponse do | |
response = | |
ask(""" | |
Please reply with any kind of message. | |
Supported message types are: | |
- text | |
- image | |
- audio | |
- video | |
- document | |
- voice | |
- location | |
- sticker | |
""") | |
end | |
card ProcessResponse when event.message.type == "image" do | |
text(""" | |
User sent an *IMAGE* message. | |
Media ID: @event.message.image.id | |
MIME type: @event.message.image.mime_type | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "video" do | |
text(""" | |
User sent a *VIDEO* message. | |
Media ID: @event.message.video.id | |
MIME type: @event.message.video.mime_type | |
Caption: @event.message.video.caption | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "document" do | |
text(""" | |
User sent a *DOCUMENT* message. | |
Media ID: @event.message.document.id | |
MIME type: @event.message.document.mime_type | |
File name: @event.message.document.filename | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "location" do | |
text(""" | |
User sent a *LOCATION* message. | |
Latitude: @event.message.location.latitude | |
Longitude: @event.message.location.longitude | |
""") | |
end | |
card ProcessResponse when event.message.type == "voice" do | |
text(""" | |
User sent a *VOICE* message. | |
Media ID: @event.message.voice.id | |
MIME type: @event.message.voice.mime_type | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "audio" do | |
text(""" | |
User sent an *AUDIO* message. | |
Media ID: @event.message.audio.id | |
MIME type: @event.message.audio.mime_type | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "sticker" do | |
text(""" | |
User sent a *STICKER* message. | |
Media ID: @event.message.sticker.id | |
Sticker Metadata: @event.message.sticker.metadata | |
MIME type: @event.message.sticker.mime_type | |
Your server can retrieve the media using our API: | |
https://whatsapp.turn.io/docs/api/media#retrieving-media | |
""") | |
end | |
card ProcessResponse when event.message.type == "text" do | |
text(""" | |
User sent a *TEXT* message. | |
Text: @response | |
""") | |
end | |
card ProcessResponse do | |
text("Unhandled message type @event.message.type") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment