Finished whatsapp

pull/3373/head
Jamie Rees 5 years ago
parent 0c7b6a8ed0
commit 8a94298a80

@ -8,14 +8,8 @@ namespace Ombi.Api.Twilio
{
public class WhatsAppApi : IWhatsAppApi
{
public async Task<string> SendMessage(WhatsAppModel message, string accountSid, string authToken)
{
// Find your Account Sid and Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
//const string accountSid = "AC8a1b6ab0d9f351be8210ccc8f7930d27";
//const string authToken = "f280272092780a770f7cd4fb0beed125";
TwilioClient.Init(accountSid, authToken);
var response =await MessageResource.CreateAsync(

@ -91,6 +91,7 @@ export interface INotificationPreferences {
}
export enum INotificationAgent {
Email = 0,
Discord = 1,
Pushbullet = 2,
@ -99,4 +100,6 @@ export enum INotificationAgent {
Slack = 5,
Mattermost = 6,
Mobile = 7,
Gotify = 8,
WhatsApp = 9
}

@ -24,6 +24,7 @@ import {
ISlackNotificationSettings,
ISonarrSettings,
ITelegramNotifcationSettings,
IWhatsAppSettings,
} from "../../interfaces";
@Injectable()
@ -52,6 +53,10 @@ export class TesterService extends ServiceHelpers {
return this.http.post<boolean>(`${this.url}mattermost`, JSON.stringify(settings), {headers: this.headers});
}
public whatsAppTest(settings: IWhatsAppSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}whatsapp`, JSON.stringify(settings), {headers: this.headers});
}
public slackTest(settings: ISlackNotificationSettings): Observable<boolean> {
return this.http.post<boolean>(`${this.url}slack`, JSON.stringify(settings), {headers: this.headers});
}

@ -28,7 +28,7 @@
</div>
<div class="md-form-field">
<div>
<button mat-raised-button type="button" color="primary">Test</button>
<button mat-raised-button type="button" color="primary" (click)="test(form)">Test</button>
</div>
</div>
</div>

@ -25,11 +25,11 @@ export class WhatsAppComponent {
return;
}
this.testerService.mattermostTest(form.value).subscribe(x => {
this.testerService.whatsAppTest(form.get("whatsAppSettings").value).subscribe(x => {
if (x) {
this.notificationService.success( "Successfully sent a Mattermost message, please check the appropriate channel");
this.notificationService.success( "Successfully sent a WhatsApp message, please check the appropriate channel");
} else {
this.notificationService.error("There was an error when sending the Mattermost message. Please check your settings");
this.notificationService.error("There was an error when sending the WhatsApp message. Please check your settings");
}
});

@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Ombi.Api.CouchPotato;
using Ombi.Api.Emby;
@ -10,7 +11,9 @@ using Ombi.Api.Plex;
using Ombi.Api.Radarr;
using Ombi.Api.SickRage;
using Ombi.Api.Sonarr;
using Ombi.Api.Twilio;
using Ombi.Attributes;
using Ombi.Core.Authentication;
using Ombi.Core.Models.UI;
using Ombi.Core.Notifications;
using Ombi.Core.Settings.Models.External;
@ -22,6 +25,7 @@ using Ombi.Notifications.Models;
using Ombi.Schedule.Jobs.Ombi;
using Ombi.Settings.Settings.Models.External;
using Ombi.Settings.Settings.Models.Notifications;
using Ombi.Store.Entities;
namespace Ombi.Controllers.V1.External
{
@ -40,7 +44,7 @@ namespace Ombi.Controllers.V1.External
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification,
ILidarrApi lidarrApi, IGotifyNotification gotifyNotification)
ILidarrApi lidarrApi, IGotifyNotification gotifyNotification, IWhatsAppApi whatsAppApi, OmbiUserManager um)
{
Service = service;
DiscordNotification = notification;
@ -62,6 +66,8 @@ namespace Ombi.Controllers.V1.External
MobileNotification = mobileNotification;
LidarrApi = lidarrApi;
GotifyNotification = gotifyNotification;
WhatsAppApi = whatsAppApi;
UserManager = um;
}
private INotificationService Service { get; }
@ -84,7 +90,8 @@ namespace Ombi.Controllers.V1.External
private INewsletterJob Newsletter { get; }
private IMobileNotification MobileNotification { get; }
private ILidarrApi LidarrApi { get; }
private IWhatsAppApi WhatsAppApi { get; }
private OmbiUserManager UserManager {get;}
/// <summary>
/// Sends a test message to discord using the provided settings
@ -459,5 +466,35 @@ namespace Ombi.Controllers.V1.External
return false;
}
}
[HttpPost("whatsapp")]
public async Task<bool> WhatsAppTest([FromBody] WhatsAppSettingsViewModel settings)
{
try
{
var user = await UserManager.Users.Include(x => x.UserNotificationPreferences).FirstOrDefaultAsync(x => x.UserName == HttpContext.User.Identity.Name);
var status = await WhatsAppApi.SendMessage(new WhatsAppModel {
From = settings.From,
Message = "This is a test from Ombi!",
To = user.UserNotificationPreferences.FirstOrDefault(x => x.Agent == NotificationAgent.WhatsApp).Value
}, settings.AccountSid, settings.AuthToken);
if (status.HasValue())
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
Log.LogError(LoggingEvents.Api, e, "Could not test Lidarr");
return false;
}
}
}
}
Loading…
Cancel
Save