Class: Teams::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/teams/router.rb

Defined Under Namespace

Classes: Route

Constant Summary collapse

CONVERSATION_UPDATE_EVENTS =
{
  "on_channel_created" => "channelCreated",
  "on_channel_deleted" => "channelDeleted",
  "on_channel_renamed" => "channelRenamed",
  "on_channel_restored" => "channelRestored",
  "on_team_archived" => "teamArchived",
  "on_team_deleted" => "teamDeleted",
  "on_team_hard_deleted" => "teamHardDeleted",
  "on_team_renamed" => "teamRenamed",
  "on_team_restored" => "teamRestored",
  "on_team_unarchived" => "teamUnarchived"
}.freeze
MESSAGE_EXTENSION_ROUTES =

Message extension (compose extension) invoke routes, using the same route names as the TypeScript and Python SDKs.

{
  "message.ext.query" => "composeExtension/query",
  "message.ext.select-item" => "composeExtension/selectItem",
  "message.ext.submit" => "composeExtension/submitAction",
  "message.ext.open" => "composeExtension/fetchTask",
  "message.ext.query-link" => "composeExtension/queryLink",
  "message.ext.anon-query-link" => "composeExtension/anonymousQueryLink",
  "message.ext.query-settings-url" => "composeExtension/querySettingUrl",
  "message.ext.setting" => "composeExtension/setting",
  "message.ext.card-button-clicked" => "composeExtension/onCardButtonClicked"
}.freeze
MESSAGE_EXTENSION_HANDLER_METHODS =
MESSAGE_EXTENSION_ROUTES.keys.to_h do |route_name|
  ["on_#{route_name.sub("message.ext.", "message_ext_").tr("-", "_")}", route_name]
end.freeze

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



7
8
9
# File 'lib/teams/router.rb', line 7

def initialize
  @routes = []
end

Instance Method Details

#matching(activity) ⇒ Object



149
150
151
# File 'lib/teams/router.rb', line 149

def matching(activity)
  @routes.select { |route| route.selector.call(activity) }
end

#on(name, &block) ⇒ Object



15
16
17
# File 'lib/teams/router.rb', line 15

def on(name, &block)
  register(name.to_s, route_selector(name.to_s), &block)
end

#on_card_search(&block) ⇒ Object

application/search invokes - Adaptive Card dynamic typeahead Input.ChoiceSet queries (choices.data / Data.Query).



77
78
79
# File 'lib/teams/router.rb', line 77

def on_card_search(&block)
  register("card.search", invoke_selector("application/search"), &block)
end

#on_conversation_update(&block) ⇒ Object

conversationUpdate activities and their channel/team lifecycle sub-events, routed by channelData.eventType with the Python method names (the eventType literals are shared by all three SDKs).



102
103
104
# File 'lib/teams/router.rb', line 102

def on_conversation_update(&block)
  register("conversation_update", ->(activity) { activity.type == "conversationUpdate" }, &block)
end

#on_dialog_open(dialog_id = nil, &block) ⇒ Object

Matches task/fetch invokes; with a dialog_id, only those whose card action data carries that "dialog_id" value.



49
50
51
# File 'lib/teams/router.rb', line 49

def on_dialog_open(dialog_id = nil, &block)
  register("dialog.open", dialog_selector("task/fetch", "dialog_id", dialog_id), &block)
end

#on_dialog_submit(action = nil, &block) ⇒ Object

Matches task/submit invokes; with an action, only those whose card action data carries that "action" value.



55
56
57
# File 'lib/teams/router.rb', line 55

def on_dialog_submit(action = nil, &block)
  register("dialog.submit", dialog_selector("task/submit", "action", action), &block)
end

#on_edit_message(&block) ⇒ Object



39
40
41
# File 'lib/teams/router.rb', line 39

def on_edit_message(&block)
  register("edit_message", message_update_event_selector("editMessage"), &block)
end

#on_meeting_end(&block) ⇒ Object



95
96
97
# File 'lib/teams/router.rb', line 95

def on_meeting_end(&block)
  register("meeting_end", event_selector("application/vnd.microsoft.meetingEnd"), &block)
end

#on_meeting_start(&block) ⇒ Object



91
92
93
# File 'lib/teams/router.rb', line 91

def on_meeting_start(&block)
  register("meeting_start", event_selector("application/vnd.microsoft.meetingStart"), &block)
end

#on_message(pattern = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/teams/router.rb', line 19

def on_message(pattern = nil, &block)
  selector = lambda do |activity|
    next false unless activity.message?
    next true if pattern.nil?

    case pattern
    when Regexp
      pattern.match?(activity.text.to_s)
    else
      activity.text.to_s == pattern.to_s
    end
  end

  register("message", selector, &block)
end

#on_message_submit(&block) ⇒ Object



71
72
73
# File 'lib/teams/router.rb', line 71

def on_message_submit(&block)
  register("message.submit", invoke_selector("message/submitAction"), &block)
end

#on_message_submit_feedback(&block) ⇒ Object

message/submitAction invokes whose actionName is "feedback" - the submissions from add_feedback's thumbs up/down UI.



83
84
85
86
87
88
89
# File 'lib/teams/router.rb', line 83

def on_message_submit_feedback(&block)
  selector = lambda do |activity|
    activity.invoke? && activity.name == "message/submitAction" &&
      activity.raw.dig("value", "actionName") == "feedback"
  end
  register("message.submit.feedback", selector, &block)
end

#on_message_update(&block) ⇒ Object



35
36
37
# File 'lib/teams/router.rb', line 35

def on_message_update(&block)
  register("messageUpdate", route_selector("messageUpdate"), &block)
end

#on_signin_failure(&block) ⇒ Object



67
68
69
# File 'lib/teams/router.rb', line 67

def (&block)
  register("signin.failure", invoke_selector("signin/failure"), &block)
end

#on_signin_token_exchange(&block) ⇒ Object



59
60
61
# File 'lib/teams/router.rb', line 59

def (&block)
  register("signin.token-exchange", invoke_selector("signin/tokenExchange"), &block)
end

#on_signin_verify_state(&block) ⇒ Object



63
64
65
# File 'lib/teams/router.rb', line 63

def (&block)
  register("signin.verify-state", invoke_selector("signin/verifyState"), &block)
end

#on_undelete_message(&block) ⇒ Object



43
44
45
# File 'lib/teams/router.rb', line 43

def on_undelete_message(&block)
  register("undelete_message", message_update_event_selector("undeleteMessage"), &block)
end

#use(&block) ⇒ Object



11
12
13
# File 'lib/teams/router.rb', line 11

def use(&block)
  register(nil, ->(_activity) { true }, &block)
end