示例#1
0
        // C# dependency installed via NuGut for access to the OneSignal API is:
        // https://github.com/Alegrowin/OneSignal.RestAPIv3.Client
        public static async Task<NotificationCreateResult> SendPushNotification(UserProfileTemporary userProfileTemporary, string title, string body)
        {
            if (string.IsNullOrEmpty(userProfileTemporary.PushUserId))
            {
                return new NotificationCreateResult();
            }

            if (title == null)
            {
                title = "";
            }

            if (body == null)
            {
                body = "";
            }

            var client = new OneSignalClient(Consts.ONE_SIGNAL_API_KEY); // Use your Api Key
            var options = new NotificationCreateOptions
            {
                AppId = new Guid(Consts.ONE_SIGNAL_APP_ID),
                IncludePlayerIds = new List<string>() { userProfileTemporary.PushUserId },
                // IncludedSegments = new List<string>() { "All" } // To send to all 
            };
            options.Headings.Add(LanguageCodes.English, title);
            options.Contents.Add(LanguageCodes.English, body.Replace("<br>", "\n").Replace("\n\n", "\n"));
            return await client.Notifications.CreateAsync(options);
        }
示例#2
0
        private async Task SaveUserProfileTemporaryAsync(CommandContext ctx, UserProfileTemporary userProfileTemporary)
        {
            var key  = "discord/users/" + ctx.User.Id;
            var dict = new Dictionary <string, object>();

            userProfileTemporary.UserId = ctx.User.Id.ToString();
            dict.Add(key, userProfileTemporary);
            await temporaryStorage.WriteAsync(dict, new CancellationToken());
        }
示例#3
0
        private async Task <UserProfileTemporary> GetUserProfileTemporaryAsync(CommandContext ctx)
        {
            var key = "discord/users/" + ctx.User.Id;
            var userProfileTemporaries = await temporaryStorage.ReadAsync <UserProfileTemporary>(new string[] { key });

            UserProfileTemporary userProfileTemporary = null;

            userProfileTemporaries.TryGetValue(key, out userProfileTemporary);
            if (userProfileTemporary == null)
            {
                userProfileTemporary = new UserProfileTemporary();
            }
            return(userProfileTemporary);
        }
示例#4
0
        public async static Task HelpAsync(ITurnContext turnContext, UserProfileTemporary userProfileTemporary, MainDialog mainDialog, CancellationToken cancellationToken)
        {
#if RELEASE_PROD
            var help1 = System.IO.File.ReadAllText("help-prod1.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help2 = System.IO.File.ReadAllText("help-prod2.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help3 = System.IO.File.ReadAllText("help-prod3.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help4 = System.IO.File.ReadAllText("help-prod4.txt").Replace("APP_VERSION", Consts.APP_VERSION);
#else
            var help1 = System.IO.File.ReadAllText("help-dev1.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help2 = System.IO.File.ReadAllText("help-dev2.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help3 = System.IO.File.ReadAllText("help-dev3.txt").Replace("APP_VERSION", Consts.APP_VERSION);
            var help4 = System.IO.File.ReadAllText("help-dev4.txt").Replace("APP_VERSION", Consts.APP_VERSION);
#endif
            await turnContext.SendActivityAsync(MessageFactory.Text(help1), cancellationToken);

            await turnContext.SendActivityAsync(MessageFactory.Text(help2), cancellationToken);

            await turnContext.SendActivityAsync(MessageFactory.Text(help3), cancellationToken);

            await turnContext.SendActivityAsync(MessageFactory.Text(help4), cancellationToken);

            if (!string.IsNullOrEmpty(turnContext.Activity.Text) && !userProfileTemporary.IsLocationSet)
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(Consts.NO_LOCATION_SET_MSG), cancellationToken);

                // Hack coz Facebook Messenge stopped showing "Send Location" button
                if (turnContext.Activity.ChannelId.Equals("facebook"))
                {
                    await turnContext.SendActivityAsync(CardFactory.CreateGetLocationFromGoogleMapsReply());
                }

                return;
            }
            else
            {
                await((AdapterWithErrorHandler)turnContext.Adapter).RepromptMainDialog(turnContext, mainDialog, cancellationToken);
                return;
            }
        }