mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Finished whatsapp
This commit is contained in:
parent
0c7b6a8ed0
commit
8a94298a80
6 changed files with 51 additions and 12 deletions
|
@ -8,14 +8,8 @@ namespace Ombi.Api.Twilio
|
||||||
{
|
{
|
||||||
public class WhatsAppApi : IWhatsAppApi
|
public class WhatsAppApi : IWhatsAppApi
|
||||||
{
|
{
|
||||||
|
|
||||||
public async Task<string> SendMessage(WhatsAppModel message, string accountSid, string authToken)
|
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);
|
TwilioClient.Init(accountSid, authToken);
|
||||||
|
|
||||||
var response =await MessageResource.CreateAsync(
|
var response =await MessageResource.CreateAsync(
|
||||||
|
|
|
@ -91,6 +91,7 @@ export interface INotificationPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum INotificationAgent {
|
export enum INotificationAgent {
|
||||||
|
|
||||||
Email = 0,
|
Email = 0,
|
||||||
Discord = 1,
|
Discord = 1,
|
||||||
Pushbullet = 2,
|
Pushbullet = 2,
|
||||||
|
@ -99,4 +100,6 @@ export enum INotificationAgent {
|
||||||
Slack = 5,
|
Slack = 5,
|
||||||
Mattermost = 6,
|
Mattermost = 6,
|
||||||
Mobile = 7,
|
Mobile = 7,
|
||||||
|
Gotify = 8,
|
||||||
|
WhatsApp = 9
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {
|
||||||
ISlackNotificationSettings,
|
ISlackNotificationSettings,
|
||||||
ISonarrSettings,
|
ISonarrSettings,
|
||||||
ITelegramNotifcationSettings,
|
ITelegramNotifcationSettings,
|
||||||
|
IWhatsAppSettings,
|
||||||
} from "../../interfaces";
|
} from "../../interfaces";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -52,6 +53,10 @@ export class TesterService extends ServiceHelpers {
|
||||||
return this.http.post<boolean>(`${this.url}mattermost`, JSON.stringify(settings), {headers: this.headers});
|
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> {
|
public slackTest(settings: ISlackNotificationSettings): Observable<boolean> {
|
||||||
return this.http.post<boolean>(`${this.url}slack`, JSON.stringify(settings), {headers: this.headers});
|
return this.http.post<boolean>(`${this.url}slack`, JSON.stringify(settings), {headers: this.headers});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="md-form-field">
|
<div class="md-form-field">
|
||||||
<div>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,11 +25,11 @@ export class WhatsAppComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.testerService.mattermostTest(form.value).subscribe(x => {
|
this.testerService.whatsAppTest(form.get("whatsAppSettings").value).subscribe(x => {
|
||||||
if (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 {
|
} 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.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Api.CouchPotato;
|
using Ombi.Api.CouchPotato;
|
||||||
using Ombi.Api.Emby;
|
using Ombi.Api.Emby;
|
||||||
|
@ -10,7 +11,9 @@ using Ombi.Api.Plex;
|
||||||
using Ombi.Api.Radarr;
|
using Ombi.Api.Radarr;
|
||||||
using Ombi.Api.SickRage;
|
using Ombi.Api.SickRage;
|
||||||
using Ombi.Api.Sonarr;
|
using Ombi.Api.Sonarr;
|
||||||
|
using Ombi.Api.Twilio;
|
||||||
using Ombi.Attributes;
|
using Ombi.Attributes;
|
||||||
|
using Ombi.Core.Authentication;
|
||||||
using Ombi.Core.Models.UI;
|
using Ombi.Core.Models.UI;
|
||||||
using Ombi.Core.Notifications;
|
using Ombi.Core.Notifications;
|
||||||
using Ombi.Core.Settings.Models.External;
|
using Ombi.Core.Settings.Models.External;
|
||||||
|
@ -22,6 +25,7 @@ using Ombi.Notifications.Models;
|
||||||
using Ombi.Schedule.Jobs.Ombi;
|
using Ombi.Schedule.Jobs.Ombi;
|
||||||
using Ombi.Settings.Settings.Models.External;
|
using Ombi.Settings.Settings.Models.External;
|
||||||
using Ombi.Settings.Settings.Models.Notifications;
|
using Ombi.Settings.Settings.Models.Notifications;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
|
||||||
namespace Ombi.Controllers.V1.External
|
namespace Ombi.Controllers.V1.External
|
||||||
{
|
{
|
||||||
|
@ -40,7 +44,7 @@ namespace Ombi.Controllers.V1.External
|
||||||
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
|
IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm,
|
||||||
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
|
IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger<TesterController> log, IEmailProvider provider,
|
||||||
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification,
|
ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification,
|
||||||
ILidarrApi lidarrApi, IGotifyNotification gotifyNotification)
|
ILidarrApi lidarrApi, IGotifyNotification gotifyNotification, IWhatsAppApi whatsAppApi, OmbiUserManager um)
|
||||||
{
|
{
|
||||||
Service = service;
|
Service = service;
|
||||||
DiscordNotification = notification;
|
DiscordNotification = notification;
|
||||||
|
@ -62,6 +66,8 @@ namespace Ombi.Controllers.V1.External
|
||||||
MobileNotification = mobileNotification;
|
MobileNotification = mobileNotification;
|
||||||
LidarrApi = lidarrApi;
|
LidarrApi = lidarrApi;
|
||||||
GotifyNotification = gotifyNotification;
|
GotifyNotification = gotifyNotification;
|
||||||
|
WhatsAppApi = whatsAppApi;
|
||||||
|
UserManager = um;
|
||||||
}
|
}
|
||||||
|
|
||||||
private INotificationService Service { get; }
|
private INotificationService Service { get; }
|
||||||
|
@ -84,7 +90,8 @@ namespace Ombi.Controllers.V1.External
|
||||||
private INewsletterJob Newsletter { get; }
|
private INewsletterJob Newsletter { get; }
|
||||||
private IMobileNotification MobileNotification { get; }
|
private IMobileNotification MobileNotification { get; }
|
||||||
private ILidarrApi LidarrApi { get; }
|
private ILidarrApi LidarrApi { get; }
|
||||||
|
private IWhatsAppApi WhatsAppApi { get; }
|
||||||
|
private OmbiUserManager UserManager {get;}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a test message to discord using the provided settings
|
/// Sends a test message to discord using the provided settings
|
||||||
|
@ -459,5 +466,35 @@ namespace Ombi.Controllers.V1.External
|
||||||
return false;
|
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…
Add table
Add a link
Reference in a new issue