Skip to content

Commit

Permalink
fix(interface/chat_bot): improve chat bot interface (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach authored Nov 28, 2022
1 parent 0a0cad9 commit 06c7629
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: placeos-driver
version: 6.6.1
version: 6.6.2
crystal: ">= 1.0.0"

dependencies:
Expand Down
51 changes: 45 additions & 6 deletions src/placeos-driver/interface/chat_bot.cr
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
require "json"

abstract class PlaceOS::Driver
module Interface::ChatBot
# drivers are expected to emit door state events on
# channel security/event/door
class Message
# NOTE:: expects messages to broadcast to a channel, such as: chat/<bot_name>/<org_id>/message

struct Id
include JSON::Serializable

def initialize(@message_id, @room_id = nil, @user_id = nil, @org_id = nil)
end

# something used to identify the message
property message_id : String

# The room ID of the message.
@[JSON::Field(key: "roomId")]
property room_id : String
property room_id : String?

# The user who sent the message
property user_id : String?

# The org sending the message.
property org_id : String?
end

struct Message
include JSON::Serializable

def initialize(@id, @text)
end

property id : Id

# The message, in plain text.
@[JSON::Field(key: "text")]
property text : String
end

struct Attachment
include JSON::Serializable

def initialize(@name, @payload)
end

property name : String

# Base64 encoded binary contents
property payload : String
end

# allows a bot responder to indicate it is replying to a message
abstract def notify_typing(id : Id)

# interface used to reply to a message
abstract def reply(id : Id, response : String, url : String? = nil, attachment : Attachment? = nil)
end
end

0 comments on commit 06c7629

Please sign in to comment.