Class: BotFramework::BotState

Inherits:
ApiBase
  • Object
show all
Defined in:
lib/bot_framework/bot_state.rb

Instance Attribute Summary

Attributes inherited from ApiBase

#service_url

Instance Method Summary collapse

Methods inherited from ApiBase

#api_delete, #api_get, #api_post, #api_request

Constructor Details

#initialize(_service_url) ⇒ BotState

Returns a new instance of BotState.



3
4
5
# File 'lib/bot_framework/bot_state.rb', line 3

def initialize(_service_url)
  @service_url = 'https://state.botframework.com'
end

Instance Method Details

#delete_state_for_user(opts = {}) ⇒ Array<String>

DeleteStateForUser Delete all data for a user in a channel (UserData and PrivateConversationData)

Parameters:

  • channel_id

    channelId

  • user_id

    id for the user on the channel

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<String>)


13
14
15
16
# File 'lib/bot_framework/bot_state.rb', line 13

def delete_state_for_user(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/users/#{opts['user_id']}"
  api_delete(uri)
end

#get_conversation_data(opts = {}) ⇒ BotData

GetConversationData get the bots data for all users in a conversation

Parameters:

  • channel_id

    the channelId

  • conversation_id

    The id for the conversation on the channel

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



25
26
27
28
29
# File 'lib/bot_framework/bot_state.rb', line 25

def get_conversation_data(opts = {})
  # opts['channel_id'] & opts['conversation_id']
  uri = "/v3/botstate/#{opts['channel_id']}/conversations/#{opts['conversation_id']}"
  BotFramework::BotData.new api_get(uri)
end

#get_private_conversation_data(opts = {}) ⇒ Object

GetPrivateConversationData get bot’s data for a single user in a conversation

Parameters:

  • channel_id

    channelId

  • conversation_id

    The id for the conversation on the channel

  • user_id

    id for the user on the channel



36
37
38
39
# File 'lib/bot_framework/bot_state.rb', line 36

def get_private_conversation_data(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/conversations/#{opts['conversation_id']}/users/#{opts['user_id']}"
  BotFramework::BotData.new api_get(uri)
end

#get_user_data(opts = {}) ⇒ BotData

GetUserData Get a bots data for the user across all conversations

Parameters:

  • channel_id

    channelId

  • user_id

    id for the user on the channel

Returns:



47
48
49
50
# File 'lib/bot_framework/bot_state.rb', line 47

def get_user_data(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/users/#{opts['user_id']}"
  BotFramework::BotData.new api_get(uri)
end

#set_conversation_data(opts = {}) ⇒ BotData

SetConversationData Update the bot’s data for all users in a conversation

Parameters:

  • channel_id

    channelId

  • conversation_id

    The id for the conversation on the channel

  • bot_data

    the new botdata

Returns:



58
59
60
61
# File 'lib/bot_framework/bot_state.rb', line 58

def set_conversation_data(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/conversations/#{opts['conversation_id']}"
  api_post(uri, opts['bot_data'])
end

#set_private_conversation_data(opts = {}) ⇒ BotData

SetPrivateConversationData Update the bot’s data for a single user in a conversation

Parameters:

  • channel_id

    channelId

  • conversation_id

    The id for the conversation on the channel

  • user_id

    id for the user on the channel

  • bot_data

    the new botdata

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



72
73
74
75
# File 'lib/bot_framework/bot_state.rb', line 72

def set_private_conversation_data(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/conversations/#{opts['conversation_id']}/users/#{opts['user_id']}"
  api_post(uri, opts['bot_data'])
end

#set_user_data(opts = {}) ⇒ BotData

SetUserData Update the bot’s data for a user

Parameters:

  • channel_id

    channelId

  • user_id

    id for the user on the channel

  • bot_data

    the new botdata

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



84
85
86
87
# File 'lib/bot_framework/bot_state.rb', line 84

def set_user_data(opts = {})
  uri = "/v3/botstate/#{opts['channel_id']}/users/#{opts['user_id']}"
  api_post(uri, opts['bot_data'])
end