public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                BotId.ToBytes(),
                ShortName.ToBytes()));
 }
Exemple #2
0
        protected override void Execute(CodeActivityContext context)
        {
            var content = new ResponsePayload
            {
                message = Message.Get(context),
                target  = Target.Get(context),
                channel = Channel.Get(context),
                botId   = BotId.Get(context)
            };

            var url = $"{ExternalURL.Get(context)}/api/v1/bots/___/mod/uipath/message";

            using (var client = new HttpClient())
                using (var request = new HttpRequestMessage(HttpMethod.Post, url))
                {
                    request.Headers.Add("Authorization", $"bearer {BotpressToken.Get(context)}");
                    var json = JsonConvert.SerializeObject(content);
                    using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
                    {
                        request.Content = stringContent;

                        using (var response = client.SendAsync(request).Result)
                        {
                            response.EnsureSuccessStatusCode();
                        }
                    }
                }
        }
        /// <summary>
        /// Called when the dialog is started and pushed onto the dialog stack.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="options">Optional, initial information to pass to the dialog.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // Update the dialog options with the runtime settings.
            DialogOptions.BotId                 = BotId.GetValue(dc.State);
            DialogOptions.SkillHostEndpoint     = new Uri(SkillHostEndpoint.GetValue(dc.State));
            DialogOptions.ConversationIdFactory = dc.Context.TurnState.Get <SkillConversationIdFactoryBase>() ?? throw new NullReferenceException("Unable to locate SkillConversationIdFactoryBase in HostContext");
            DialogOptions.SkillClient           = dc.Context.TurnState.Get <BotFrameworkClient>() ?? throw new NullReferenceException("Unable to locate BotFrameworkClient in HostContext");
            DialogOptions.ConversationState     = dc.Context.TurnState.Get <ConversationState>() ?? throw new NullReferenceException($"Unable to get an instance of {nameof(ConversationState)} from TurnState.");
            DialogOptions.ConnectionName        = ConnectionName.GetValue(dc.State);

            // Set the skill to call
            DialogOptions.Skill.Id            = DialogOptions.Skill.AppId = SkillAppId.GetValue(dc.State);
            DialogOptions.Skill.SkillEndpoint = new Uri(SkillEndpoint.GetValue(dc.State));

            // Store the initialized DialogOptions in state so we can restore these values when the dialog is resumed.
            dc.ActiveDialog.State[_dialogOptionsStateKey] = DialogOptions;

            // Get the activity to send to the skill.
            Activity activity = null;

            if (Activity != null && ActivityProcessed.GetValue(dc.State))
            {
                // The parent consumed the activity in context, use the Activity property to start the skill.
                activity = await Activity.BindAsync(dc, cancellationToken : cancellationToken).ConfigureAwait(false);
            }

            // Call the base to invoke the skill
            // (If the activity has not been processed, send the turn context activity to the skill (pass through)).
            return(await base.BeginDialogAsync(dc, new BeginSkillDialogOptions { Activity = activity ?? dc.Context.Activity }, cancellationToken).ConfigureAwait(false));
        }
Exemple #4
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            var dcState = dc.GetState();

            if (Disabled != null && Disabled.GetValue(dcState))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // Update the dialog options with the runtime settings.
            DialogOptions.BotId                 = BotId.GetValue(dcState);
            DialogOptions.SkillHostEndpoint     = new Uri(SkillHostEndpoint.GetValue(dcState));
            DialogOptions.ConversationIdFactory = HostContext.Current.Get <SkillConversationIdFactoryBase>() ?? throw new NullReferenceException("Unable to locate SkillConversationIdFactoryBase in HostContext");
            DialogOptions.SkillClient           = HostContext.Current.Get <BotFrameworkClient>() ?? throw new NullReferenceException("Unable to locate BotFrameworkClient in HostContext");
            DialogOptions.ConversationState     = dc.Context.TurnState.Get <ConversationState>() ?? throw new NullReferenceException($"Unable to get an instance of {nameof(ConversationState)} from TurnState.");

            // Set the skill to call
            DialogOptions.Skill.Id            = DialogOptions.Skill.AppId = SkillAppId.GetValue(dcState);
            DialogOptions.Skill.SkillEndpoint = new Uri(SkillEndpoint.GetValue(dcState));

            // Get the activity to send to the skill.
            var activity = await Activity.BindToData(dc.Context, dcState).ConfigureAwait(false);

            // Call the base to invoke the skill
            return(await base.BeginDialogAsync(dc, new BeginSkillDialogOptions { Activity = activity }, cancellationToken).ConfigureAwait(false));
        }
Exemple #5
0
 public override int GetHashCode()
 {
     return(UserId.GetHashCode() +
            ConversationId.GetHashCode() +
            BotId.GetHashCode() +
            ChannelId.GetHashCode());
 }
Exemple #6
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                BotId.ToBytes(),
                Scope.ToBytes(),
                PublicKey.ToBytes()));
 }
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                BotId.ToBytes(),
                Scope.ToBytes(),
                PublicKey.ToBytes(),
                ValueHashes.ToBytes(),
                Credentials.ToBytes()));
 }
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = ServiceUrl != null?ServiceUrl.GetHashCode() : 0;

                hashCode = (hashCode * 397) ^ (ChannelId != null ? ChannelId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ConversationId != null ? ConversationId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (BotId != null ? BotId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (UserId != null ? UserId.GetHashCode() : 0);
                return(hashCode);
            }
        }
Exemple #9
0
        public byte[] Encode()
        {
            var buffer = new byte[Size];

            using (var w = new BinaryWriter(new MemoryStream(buffer)))
            {
                w.Write(Padding);
                w.Write(MessageId);
                w.Write(PayloadSize);
                w.Write(CorrelationId);
                w.Write(Ttl);
                w.Write(BotId.ToByteArray());
            }
            return(buffer);
        }
        public async Task AnswerInlineQueryWithValidationAsync(string inlineQueryId, IReadOnlyCollection <InlineQueryResult> results, int?cacheTime = null,
                                                               bool isPersonal = false, string?nextOffset = null, string?switchPmText = null, string?switchPmParameter = null,
                                                               CancellationToken cancellationToken = default)
        {
            ISet <string> processedIds = new HashSet <string>();

            foreach (var result in results)
            {
                if (!processedIds.Add(result.Id))
                {
                    myTelemetryClient.TrackException(
                        new DuplicateNameException(result.Id), new Dictionary <string, string?> {
                        { nameof(ITelegramBotClient.BotId), BotId.ToString() }
                    });
                }
            }
            await this.AnswerInlineQueryAsync(inlineQueryId, results, cacheTime, isPersonal, nextOffset, switchPmText, switchPmParameter, cancellationToken)
            .ConfigureAwait(false);
        }
Exemple #11
0
 public override void ToStream(Stream output)
 {
     output.Write(TLUtils.SignatureToBytes(Signature));
     BotId.ToStream(output);
     ShortName.ToStream(output);
 }
Exemple #12
0
 public JoinRace(string name, string key, string track = "keimola", int opponents = 0)
 {
     this.botId = new BotId();
     this.botId.name = name;
     this.botId.key = key;
     this.trackName = track;
     this.carCount = opponents + 1;
 }
Exemple #13
0
        public FSharpOption <FSharpFunc <Tuple <Market, Selection, BotParameters, IBfexplorerService>, Bot> > GetBotCreator(BotId botId)
        {
            if (GetIsMyBot(botId))
            {
                var func = myBotsCreators[botId.Id - 200];

                return(FSharpOption <FSharpFunc <Tuple <Market, Selection, BotParameters, IBfexplorerService>, Bot> > .Some(func));
            }
            else
            {
                return(FSharpOption <FSharpFunc <Tuple <Market, Selection, BotParameters, IBfexplorerService>, Bot> > .None);
            }
        }
Exemple #14
0
 public bool GetIsMyBot(BotId botId)
 {
     // Check valid range of your bot/s id/s. Bfexplorer BotId starts from 0, use your unique number range for bot identification.
     //return botId.Id >= 200 && botId.Id <= 209; // If you have got 10 bots
     return(botId.Id >= 200 && botId.Id <= 202);
 }