-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEchoBot.old.fs
78 lines (64 loc) · 4.19 KB
/
EchoBot.old.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
namespace EchoBotV4
open System.Threading.Tasks;
open Microsoft.Bot.Builder;
open System.Threading
open Microsoft.Bot.Schema
module Async =
let AwaitTaskVoid : (Task -> Async<unit>) =
Async.AwaitIAsyncResult >> Async.Ignore
type EchoBotOld(accessors:EchoBotAccessors) =
do printfn "In EchoBot init %A" accessors
interface IBot with
member this.OnTurnAsync (turnContext : ITurnContext, cancellationToken: CancellationToken ) =
async {
if (turnContext.Activity.Type = ActivityTypes.Message) then
// Get the conversation state from the turn context.
let! state = accessors.CounterState.GetAsync(turnContext, fun () -> new CounterState()) |> Async.AwaitTask
// Bump the turn count for this conversation.
state.TurnCount <- state.TurnCount + 1
// Set the property using the accessor.
do! accessors.CounterState.SetAsync(turnContext, state) |> Async.AwaitTaskVoid
// Save the new turn count into the conversation state.
do! accessors.ConversationState.SaveChangesAsync(turnContext) |> Async.AwaitTaskVoid
// Echo back to the user whatever they typed.
let responseMessage = sprintf "Turn %A: You sent '%A'\n" state.TurnCount turnContext.Activity.Text
do! turnContext.SendActivityAsync(responseMessage) |> Async.AwaitTaskVoid
else
do! turnContext.SendActivityAsync(sprintf "%A event detected" turnContext.Activity.Type) |> Async.AwaitTaskVoid
} |> Async.StartAsTask :> Task
member this.testMethod (turnContext : ITurnContext, cancellationToken: CancellationToken ) =
async {
if (turnContext.Activity.Type = ActivityTypes.Message) then
// Get the conversation state from the turn context.
let! state = accessors.CounterState.GetAsync(turnContext, fun () -> new CounterState()) |> Async.AwaitTask
// Bump the turn count for this conversation.
state.TurnCount <- state.TurnCount + 1
// Set the property using the accessor.
do! accessors.CounterState.SetAsync(turnContext, state) |> Async.AwaitTaskVoid
// Save the new turn count into the conversation state.
do! accessors.ConversationState.SaveChangesAsync(turnContext) |> Async.AwaitTaskVoid
// Echo back to the user whatever they typed.
let responseMessage = sprintf "Turn %A: You sent '%A'\n" state.TurnCount turnContext.Activity.Text
do! turnContext.SendActivityAsync(responseMessage) |> Async.AwaitTaskVoid
else
do! turnContext.SendActivityAsync(sprintf "%A event detected" turnContext.Activity.Type) |> Async.AwaitTaskVoid
} |> Async.StartAsTask :> Task
member this.OnTurnAsync2 (turnContext : ITurnContext, cancellationToken: CancellationToken ) =
match turnContext.Activity.Type with
| ActivityTypes.Message ->
turnContext.SendActivityAsync("Hi from F#!!") |> ignore
let state =
accessors.CounterState.GetAsync(turnContext,fun () -> new CounterState())
|> Async.AwaitTask
|> Async.RunSynchronously
// Bump the turn count for this conversation.
state.TurnCount <- state.TurnCount + 1
// Set the property using the accessor.
accessors.CounterState.SetAsync(turnContext, state) |> ignore
// Save the new turn count into the conversation state.
accessors.ConversationState.SaveChangesAsync(turnContext) |> ignore
// Echo back to the user whatever they typed.
let responseMessage = sprintf "Turn %i: You sent '%s'\n" state.TurnCount turnContext.Activity.Text
turnContext.SendActivityAsync(responseMessage) :> Task
| _ ->
turnContext.SendActivityAsync(sprintf "{%s} event detected" turnContext.Activity.Type) :> Task